Skip to content

Commit

Permalink
feat: sleep 10ms while trying to acquire exclusive lock (#65)
Browse files Browse the repository at this point in the history
Signed-off-by: MrCroxx <mrcroxx@outlook.com>
  • Loading branch information
MrCroxx committed Jul 13, 2023
1 parent 0792d14 commit 0172d33
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
5 changes: 4 additions & 1 deletion foyer-storage/src/admission/rated_random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ where
V: Value,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("DynamicRandom").finish()
f.debug_struct("DynamicRandom")
.field("rate", &self.rate)
.field("probability", &self.probability.load(Ordering::Relaxed))
.finish()
}
}

Expand Down
15 changes: 9 additions & 6 deletions foyer-storage/src/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,13 +555,16 @@ impl<A: BufferAllocator> ErwLock<A> {
can_physical_read: bool,
) -> OwnedRwLockWriteGuard<RegionInner<A>> {
loop {
let guard = self.inner.clone().write_owned().await;
let is_ready = (can_write || guard.writers == 0)
&& (can_buffered_read || guard.buffered_readers == 0)
&& (can_physical_read || guard.physical_readers == 0);
if is_ready {
return guard;
{
let guard = self.inner.clone().write_owned().await;
let is_ready = (can_write || guard.writers == 0)
&& (can_buffered_read || guard.buffered_readers == 0)
&& (can_physical_read || guard.physical_readers == 0);
if is_ready {
return guard;
}
}
tokio::time::sleep(std::time::Duration::from_millis(10)).await;
}
}
}
1 change: 0 additions & 1 deletion foyer-storage/src/region_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ where
}
}

#[tracing::instrument(skip(self))]
pub fn clean_regions(&self) -> &AsyncQueue<RegionId> {
&self.clean_regions
}
Expand Down
4 changes: 4 additions & 0 deletions foyer-storage/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ where
Ok(())
}

#[tracing::instrument(skip(self))]
pub async fn insert(&self, key: K, value: V) -> Result<bool> {
let _timer = self.metrics.latency_insert.start_timer();

Expand Down Expand Up @@ -257,6 +258,7 @@ where
Ok(true)
}

#[tracing::instrument(skip(self))]
pub async fn lookup(&self, key: &K) -> Result<Option<V>> {
let now = Instant::now();

Expand Down Expand Up @@ -300,6 +302,7 @@ where
res
}

#[tracing::instrument(skip(self))]
pub fn remove(&self, key: &K) {
let _timer = self.metrics.latency_remove.start_timer();

Expand Down Expand Up @@ -335,6 +338,7 @@ where
Ok(())
}

#[tracing::instrument(skip(self))]
async fn recover(&self, concurrency: usize) -> Result<()> {
tracing::info!("start store recovery");

Expand Down

0 comments on commit 0172d33

Please sign in to comment.