Skip to content

Commit

Permalink
Merge branch 'main' into bugfix/meta-query-multiple-alternatives
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaskrause authored Sep 25, 2024
2 parents 492ee9d + 7b77e50 commit 159e609
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
6 changes: 1 addition & 5 deletions cli/src/bin/annis_bench_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ pub fn create_query_input<M>(
query_language: QueryLanguage::AQL,
timeout: None,
};
let count = if let Ok(count) = cs.count(search_query) {
count
} else {
0
};
let count = cs.count(search_query).unwrap_or_default();
assert_eq!(def.count, count);
});
});
Expand Down
37 changes: 23 additions & 14 deletions graphannis/src/annis/db/corpusstorage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1408,28 +1408,16 @@ impl CorpusStorage {
db.apply_update(update, |_| {})?;
}
// start background thread to persists the results

let active_background_workers = self.active_background_workers.clone();
{
let (lock, _cvar) = &*active_background_workers;
let mut nr_active_background_workers = lock.lock()?;
*nr_active_background_workers += 1;
}
thread::spawn(move || {
trace!("Starting background thread to sync WAL updates");
let lock = db_entry.read().unwrap();
if let Ok(db) = get_read_or_error(&lock) {
let db: &AnnotationGraph = db;
if let Err(e) = db.background_sync_wal_updates() {
error!("Can't sync changes in background thread: {:?}", e);
} else {
trace!("Finished background thread to sync WAL updates");
}
if let Err(err) = sync_wal_updates_in_background(db_entry, active_background_workers) {
error!("Error in WAL update background thread: {}", err);
}
let (lock, cvar) = &*active_background_workers;
let mut nr_active_background_workers = lock.lock().unwrap();
*nr_active_background_workers -= 1;
cvar.notify_all();
});

Ok(())
Expand Down Expand Up @@ -2739,3 +2727,24 @@ fn create_lockfile_for_directory(db_dir: &Path) -> Result<File> {

Ok(lock_file)
}

fn sync_wal_updates_in_background(
db_entry: Arc<RwLock<CacheEntry>>,
active_background_workers: Arc<(Mutex<usize>, Condvar)>,
) -> Result<()> {
trace!("Starting background thread to sync WAL updates");
let lock = db_entry.read()?;
if let Ok(db) = get_read_or_error(&lock) {
let db: &AnnotationGraph = db;
if let Err(e) = db.background_sync_wal_updates() {
error!("Can't sync changes in background thread: {:?}", e);
} else {
trace!("Finished background thread to sync WAL updates");
}
}
let (lock, cvar) = &*active_background_workers;
let mut nr_active_background_workers = lock.lock()?;
*nr_active_background_workers -= 1;
cvar.notify_all();
Ok(())
}

0 comments on commit 159e609

Please sign in to comment.