mirror of
https://github.com/deuxfleurs-org/garage.git
synced 2026-08-24 11:36:31 +00:00
add error case for layout not ready, and fail earlier in many places
This commit is contained in:
@@ -105,7 +105,7 @@ impl LayoutManager {
|
||||
}
|
||||
|
||||
pub fn add_table(&self, table_name: &'static str) {
|
||||
let first_version = self.layout().versions().first().unwrap().version;
|
||||
let first_version = self.layout().inner().versions.first().unwrap().version;
|
||||
|
||||
self.table_sync_version
|
||||
.lock()
|
||||
@@ -139,19 +139,20 @@ impl LayoutManager {
|
||||
|
||||
// ---- ACK LOCKING ----
|
||||
|
||||
pub fn write_lock_with<T, F>(self: &Arc<Self>, f: F) -> WriteLock<T>
|
||||
pub fn write_lock_with<T, F>(self: &Arc<Self>, f: F) -> Result<WriteLock<T>, Error>
|
||||
where
|
||||
F: FnOnce(&LayoutHelper) -> T,
|
||||
F: FnOnce(&[LayoutVersion]) -> T,
|
||||
{
|
||||
let layout = self.layout();
|
||||
let version = layout.current().version;
|
||||
let value = f(&layout);
|
||||
let current_version = layout.current()?.version;
|
||||
let versions = layout.versions()?;
|
||||
let value = f(versions);
|
||||
layout
|
||||
.ack_lock
|
||||
.get(&version)
|
||||
.get(¤t_version)
|
||||
.unwrap()
|
||||
.fetch_add(1, Ordering::Relaxed);
|
||||
WriteLock::new(version, self, value)
|
||||
Ok(WriteLock::new(current_version, self, value))
|
||||
}
|
||||
|
||||
// ---- INTERNALS ---
|
||||
@@ -369,7 +370,7 @@ impl<T> Drop for WriteLock<T> {
|
||||
let layout = self.layout_manager.layout(); // acquire read lock
|
||||
if let Some(counter) = layout.ack_lock.get(&self.layout_version) {
|
||||
let prev_lock = counter.fetch_sub(1, Ordering::Relaxed);
|
||||
if prev_lock == 1 && layout.current().version > self.layout_version {
|
||||
if prev_lock == 1 && layout.current().unwrap().version > self.layout_version {
|
||||
drop(layout); // release read lock, write lock will be acquired
|
||||
self.layout_manager.ack_new_version();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user