Skip to content

Commit 9a7eff2

Browse files
authored
Fix potential stuck in region cache (#345)
* Fix clippy::crate_in_macro_def warnings Signed-off-by: Apricity <[email protected]> * Fix potential stuck in region cache Signed-off-by: Apricity <[email protected]>
1 parent 5714b2f commit 9a7eff2

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

src/region_cache.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,11 @@ impl<C: RetryClientTrait> RegionCache<C> {
100100

101101
// check concurrent requests
102102
let notify = region_cache_guard.on_my_way_id.get(&id).cloned();
103+
let notified = notify.as_ref().map(|notify| notify.notified());
103104
drop(region_cache_guard);
104105

105-
if let Some(n) = notify {
106-
n.notified().await;
106+
if let Some(n) = notified {
107+
n.await;
107108
continue;
108109
} else {
109110
return self.read_through_region_by_id(id).await;

src/request/shard.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ macro_rules! shardable_key {
8282

8383
fn shards(
8484
&self,
85-
pd_client: &std::sync::Arc<impl crate::pd::PdClient>,
85+
pd_client: &std::sync::Arc<impl $crate::pd::PdClient>,
8686
) -> futures::stream::BoxStream<
8787
'static,
88-
crate::Result<(Self::Shard, crate::store::RegionStore)>,
88+
$crate::Result<(Self::Shard, $crate::store::RegionStore)>,
8989
> {
90-
crate::store::store_stream_for_keys(
90+
$crate::store::store_stream_for_keys(
9191
std::iter::once(self.key.clone()),
9292
pd_client.clone(),
9393
)
@@ -96,8 +96,8 @@ macro_rules! shardable_key {
9696
fn apply_shard(
9797
&mut self,
9898
mut shard: Self::Shard,
99-
store: &crate::store::RegionStore,
100-
) -> crate::Result<()> {
99+
store: &$crate::store::RegionStore,
100+
) -> $crate::Result<()> {
101101
self.set_context(store.region_with_leader.context()?);
102102
assert!(shard.len() == 1);
103103
self.set_key(shard.pop().unwrap());
@@ -115,21 +115,21 @@ macro_rules! shardable_keys {
115115

116116
fn shards(
117117
&self,
118-
pd_client: &std::sync::Arc<impl crate::pd::PdClient>,
118+
pd_client: &std::sync::Arc<impl $crate::pd::PdClient>,
119119
) -> futures::stream::BoxStream<
120120
'static,
121-
crate::Result<(Self::Shard, crate::store::RegionStore)>,
121+
$crate::Result<(Self::Shard, $crate::store::RegionStore)>,
122122
> {
123123
let mut keys = self.keys.clone();
124124
keys.sort();
125-
crate::store::store_stream_for_keys(keys.into_iter(), pd_client.clone())
125+
$crate::store::store_stream_for_keys(keys.into_iter(), pd_client.clone())
126126
}
127127

128128
fn apply_shard(
129129
&mut self,
130130
shard: Self::Shard,
131-
store: &crate::store::RegionStore,
132-
) -> crate::Result<()> {
131+
store: &$crate::store::RegionStore,
132+
) -> $crate::Result<()> {
133133
self.set_context(store.region_with_leader.context()?);
134134
self.set_keys(shard.into_iter().map(Into::into).collect());
135135
Ok(())
@@ -146,18 +146,18 @@ macro_rules! shardable_range {
146146

147147
fn shards(
148148
&self,
149-
pd_client: &Arc<impl crate::pd::PdClient>,
150-
) -> BoxStream<'static, crate::Result<(Self::Shard, crate::store::RegionStore)>> {
149+
pd_client: &Arc<impl $crate::pd::PdClient>,
150+
) -> BoxStream<'static, $crate::Result<(Self::Shard, $crate::store::RegionStore)>> {
151151
let start_key = self.start_key.clone().into();
152152
let end_key = self.end_key.clone().into();
153-
crate::store::store_stream_for_range((start_key, end_key), pd_client.clone())
153+
$crate::store::store_stream_for_range((start_key, end_key), pd_client.clone())
154154
}
155155

156156
fn apply_shard(
157157
&mut self,
158158
shard: Self::Shard,
159-
store: &crate::store::RegionStore,
160-
) -> crate::Result<()> {
159+
store: &$crate::store::RegionStore,
160+
) -> $crate::Result<()> {
161161
self.set_context(store.region_with_leader.context()?);
162162

163163
self.set_start_key(shard.0.into());

0 commit comments

Comments
 (0)