Skip to content

Commit

Permalink
throttle writes to occur one bucket at a time
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwashington committed Mar 14, 2023
1 parent 0b0f95c commit 5f49689
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions runtime/src/bucket_map_holder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ pub struct BucketMapHolder<T: IndexValue, U: DiskIndexValue + From<T> + Into<T>>
/// Note startup is an optimization and is not required for correctness.
startup: AtomicBool,
_phantom: PhantomData<T>,

pub(crate) write_active: AtomicBool,
}

impl<T: IndexValue, U: DiskIndexValue + From<T> + Into<T>> Debug for BucketMapHolder<T, U> {
Expand Down
10 changes: 9 additions & 1 deletion runtime/src/in_mem_accounts_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,10 @@ impl<T: IndexValue, U: DiskIndexValue + From<T> + Into<T>> InMemAccountsIndex<T,
return;
}

let write_to_disk = self.get_write_bucket_to_disk();
let mut write_to_disk = self.get_write_bucket_to_disk();
if write_to_disk {
write_to_disk = !self.storage.write_active.swap(true, Ordering::Relaxed);
}
Self::update_stat(
if write_to_disk {
&self.stats().buckets_written_to_disk
Expand Down Expand Up @@ -1258,6 +1261,11 @@ impl<T: IndexValue, U: DiskIndexValue + From<T> + Into<T>> InMemAccountsIndex<T,
self.set_has_aged(current_age, can_advance_age);
}
}

if write_to_disk {
// no longer active
self.storage.write_active.store(false, Ordering::Relaxed);
}
}

/// calculate the estimated size of the in-mem index
Expand Down

0 comments on commit 5f49689

Please sign in to comment.