From 66e321cac169ccf530658e5870cee8ddaec71a09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=82=8E=E6=B3=BC?= Date: Wed, 27 Sep 2023 22:03:57 +0800 Subject: [PATCH] remove lifetime param, encountered the bug: Higher ranked lifetime error when tryng to see that a future is send. #114046 https://github.com/rust-lang/rust/issues/114046 --- .../src/sm_v002/leveled_store/level_data.rs | 21 ++++------- .../src/sm_v002/leveled_store/leveled_map.rs | 35 ++++++++----------- .../src/sm_v002/leveled_store/map_api.rs | 24 +++++-------- .../leveled_store/static_leveled_map.rs | 6 ++-- 4 files changed, 33 insertions(+), 53 deletions(-) diff --git a/src/meta/raft-store/src/sm_v002/leveled_store/level_data.rs b/src/meta/raft-store/src/sm_v002/leveled_store/level_data.rs index 074b9d98423f0..1a9e290ed7e1f 100644 --- a/src/meta/raft-store/src/sm_v002/leveled_store/level_data.rs +++ b/src/meta/raft-store/src/sm_v002/leveled_store/level_data.rs @@ -82,18 +82,16 @@ impl LevelData { } } -impl<'d> MapApiRO<'d, String> for &'d LevelData { +impl<'d> MapApiRO for &'d LevelData { type GetFut<'f, Q> = impl Future::V>> + 'f where Self: 'f, - 'd: 'f, String: Borrow, Q: Ord + Send + Sync + ?Sized, Q: 'f; fn get<'f, Q>(self, key: &'f Q) -> Self::GetFut<'f, Q> where - // 'd: 'f, String: Borrow, Q: Ord + Send + Sync + ?Sized, Q: 'f, @@ -101,19 +99,17 @@ impl<'d> MapApiRO<'d, String> for &'d LevelData { async move { self.kv.get(key).cloned().unwrap_or(Marked::empty()) } } - type RangeFut<'f, Q, R> = impl Future::V>)>> + type RangeFut<'f, Q, R> = impl Future::V>)>> + 'f where Self: 'f, - 'd: 'f, String: Borrow, R: RangeBounds + Send + Sync + Clone, - R: 'f, + R: 'f, Q: Ord + Send + Sync + ?Sized, Q: 'f; fn range<'f, Q, R>(self, range: R) -> Self::RangeFut<'f, Q, R> where - 'd: 'f, String: Borrow, Q: Ord + Send + Sync + ?Sized, R: RangeBounds + Clone + Send + Sync, @@ -126,7 +122,7 @@ impl<'d> MapApiRO<'d, String> for &'d LevelData { } } -impl<'me> MapApi<'me, String> for &'me mut LevelData { +impl<'me> MapApi for &'me mut LevelData { type RO<'o> = &'o LevelData where Self: 'o; fn to_ro<'o>(&'o self) -> Self::RO<'o> { @@ -143,7 +139,7 @@ impl<'me> MapApi<'me, String> for &'me mut LevelData { value: Option<(::V, Option)>, ) -> Self::SetFut<'f> where - 'me: 'f, + Self: 'f, { // The chance it is the bottom level is very low in a loaded system. // Thus we always tombstone the key if it is None. @@ -167,11 +163,10 @@ impl<'me> MapApi<'me, String> for &'me mut LevelData { } } -impl<'d> MapApiRO<'d, ExpireKey> for &'d LevelData { +impl<'d> MapApiRO for &'d LevelData { type GetFut<'f, Q> = impl Future::V>> + 'f where Self: 'f, - 'd: 'f, ExpireKey: Borrow, Q: Ord + Send + Sync + ?Sized, Q: 'f; @@ -189,7 +184,6 @@ impl<'d> MapApiRO<'d, ExpireKey> for &'d LevelData { type RangeFut<'f, Q, R> = impl Future::V>)>> + 'f where Self: 'f, - 'd: 'f, ExpireKey: Borrow, R: RangeBounds + Send + Sync + Clone, R: 'f, @@ -198,7 +192,6 @@ impl<'d> MapApiRO<'d, ExpireKey> for &'d LevelData { fn range<'f, Q, R>(self, range: R) -> Self::RangeFut<'f, Q, R> where - 'd: 'f, ExpireKey: Borrow, Q: Ord + Send + Sync + ?Sized, R: RangeBounds + Clone + Send + Sync, @@ -215,7 +208,7 @@ impl<'d> MapApiRO<'d, ExpireKey> for &'d LevelData { } } -impl<'me> MapApi<'me, ExpireKey> for &'me mut LevelData { +impl<'me> MapApi for &'me mut LevelData { type RO<'o> = &'o LevelData where Self: 'o; diff --git a/src/meta/raft-store/src/sm_v002/leveled_store/leveled_map.rs b/src/meta/raft-store/src/sm_v002/leveled_store/leveled_map.rs index 0416e8c5dad52..e563349d579ac 100644 --- a/src/meta/raft-store/src/sm_v002/leveled_store/leveled_map.rs +++ b/src/meta/raft-store/src/sm_v002/leveled_store/leveled_map.rs @@ -58,23 +58,22 @@ impl<'d> LeveledRef<'d> { } } -impl<'d, K> MapApiRO<'d, K> for LeveledRef<'d> +impl<'d, K> MapApiRO for LeveledRef<'d> where K: MapKey + fmt::Debug, - // &'d LevelData: MapApiRO<'d, K>, - for<'him> &'him LevelData: MapApiRO<'him, K>, + // &'d LevelData: MapApiRO, + for<'him> &'him LevelData: MapApiRO, + // &'him LevelData: MapApiRO, { type GetFut<'f, Q> = impl Future> + 'f where Self: 'f, - 'd: 'f, K: Borrow, Q: Ord + Send + Sync + ?Sized, Q: 'f; fn get<'f, Q>(self, key: &'f Q) -> Self::GetFut<'f, Q> where - 'd: 'f, K: Borrow, Q: Ord + Send + Sync + ?Sized, Q: 'f, @@ -90,10 +89,9 @@ where } } - type RangeFut<'f, Q, R> = impl Future)>> + type RangeFut<'f, Q, R> = impl Future)>> + 'f where Self: 'f, - 'd: 'f, K: Borrow, R: RangeBounds + Send + Sync + Clone, R:'f, @@ -102,7 +100,6 @@ where fn range<'f, Q, R>(self, range: R) -> Self::RangeFut<'f, Q, R> where - 'd: 'f, K: Borrow, R: RangeBounds + Clone + Send + Sync, R: 'f, @@ -176,15 +173,14 @@ impl<'d> LeveledRefMut<'d> { // Because `LeveledRefMut` has a mut ref of lifetime 'd, // `self` must outlive 'd otherwise there will be two mut ref. -impl<'d, K> MapApiRO<'d, K> for LeveledRefMut<'d> +impl<'d, K> MapApiRO for LeveledRefMut<'d> where K: MapKey, - for<'him> &'him LevelData: MapApiRO<'him, K>, + for<'him> &'him LevelData: MapApiRO, { type GetFut<'f, Q> = impl Future> + 'f where Self: 'f, - 'd: 'f, K: Borrow, Q: Ord + Send + Sync + ?Sized, Q: 'f; @@ -209,7 +205,6 @@ where type RangeFut<'f, Q, R> = impl Future)>> +'f where Self: 'f, - 'd: 'f, K: Borrow, R: RangeBounds + Send + Sync + Clone, R: 'f, @@ -227,11 +222,11 @@ where } } -impl<'d, K> MapApi<'d, K> for LeveledRefMut<'d> +impl<'d, K> MapApi for LeveledRefMut<'d> where K: MapKey, - for<'him> &'him LevelData: MapApiRO<'him, K>, - for<'him> &'him mut LevelData: MapApi<'him, K>, + for<'him> &'him LevelData: MapApiRO, + for<'him> &'him mut LevelData: MapApi, { type RO<'o> = LeveledRef<'o> where Self: 'o; @@ -342,10 +337,10 @@ impl LeveledMap { } } -impl<'d, K> MapApiRO<'d, K> for &'d LeveledMap +impl<'d, K> MapApiRO for &'d LeveledMap where K: MapKey + fmt::Debug, - for<'him> &'him LevelData: MapApiRO<'him, K>, + for<'him> &'him LevelData: MapApiRO, { type GetFut<'f, Q> = impl Future> + 'f where @@ -386,11 +381,11 @@ where } } -impl<'me, K> MapApi<'me, K> for &'me mut LeveledMap +impl<'me, K> MapApi for &'me mut LeveledMap where K: MapKey, - for<'e> &'e LevelData: MapApiRO<'e, K>, - for<'him> &'him mut LevelData: MapApi<'him, K>, + for<'e> &'e LevelData: MapApiRO, + for<'him> &'him mut LevelData: MapApi, { type RO<'o> = LeveledRef<'o> where Self: 'o; diff --git a/src/meta/raft-store/src/sm_v002/leveled_store/map_api.rs b/src/meta/raft-store/src/sm_v002/leveled_store/map_api.rs index 79d55fdfa70ff..ad7e974306018 100644 --- a/src/meta/raft-store/src/sm_v002/leveled_store/map_api.rs +++ b/src/meta/raft-store/src/sm_v002/leveled_store/map_api.rs @@ -57,13 +57,12 @@ impl MapValue for V where V: Clone + Send + Sync + Unpin + 'static {} /// /// There is no lifetime constraint on the trait, /// and it's the implementation's duty to specify a valid lifetime constraint. -pub(in crate::sm_v002) trait MapApiRO<'d, K>: Send + Sync +pub(in crate::sm_v002) trait MapApiRO: Send + Sync where K: MapKey { type GetFut<'f, Q>: Future> where Self: 'f, - 'd: 'f, K: Borrow, Q: Ord + Send + Sync + ?Sized, Q: 'f; @@ -78,7 +77,6 @@ where K: MapKey type RangeFut<'f, Q, R>: Future)>> where Self: 'f, - 'd: 'f, K: Borrow, R: RangeBounds + Send + Sync + Clone, R: 'f, @@ -97,10 +95,10 @@ where K: MapKey } /// Provide a read-write key-value map API set, used to access state machine data. -pub(in crate::sm_v002) trait MapApi<'d, K>: MapApiRO<'d, K> +pub(in crate::sm_v002) trait MapApi: MapApiRO where K: MapKey { - type RO<'o>: MapApiRO<'o, K> + type RO<'o>: MapApiRO where Self: 'o; fn to_ro<'o>(&'o self) -> Self::RO<'o>; @@ -124,7 +122,7 @@ impl MapApiExt { ) -> (Marked, Marked) where K: MapKey, - &'d mut T: MapApi<'d, K>, + &'d mut T: MapApi, { // let got = s.to_ro().get(&key).await; @@ -147,7 +145,7 @@ impl MapApiExt { ) -> (Marked, Marked) where K: MapKey, - &'d mut T: MapApi<'d, K>, + &'d mut T: MapApi, { let got = s.to_ro().get(&key).await; @@ -161,18 +159,17 @@ impl MapApiExt { } } -impl<'ro_me, 'ro_d, K, T> MapApiRO<'ro_d, K> for &'ro_me mut T +impl<'ro_me, K, T> MapApiRO for &'ro_me mut T where K: MapKey, - &'ro_me T: MapApiRO<'ro_d, K>, + &'ro_me T: MapApiRO, K: Ord + Send + Sync + 'static, T: Send + Sync, { - type GetFut<'f, Q> = <&'ro_me T as MapApiRO<'ro_d, K>>::GetFut<'f, Q> + type GetFut<'f, Q> = <&'ro_me T as MapApiRO>::GetFut<'f, Q> where Self: 'f, 'ro_me: 'f, - 'ro_d: 'f, K: Borrow, Q: Ord + Send + Sync + ?Sized, Q: 'f; @@ -180,18 +177,16 @@ where fn get<'f, Q>(self, key: &'f Q) -> Self::GetFut<'f, Q> where 'ro_me: 'f, - 'ro_d: 'f, K: Borrow, Q: Ord + Send + Sync + ?Sized, { (&*self).get(key) } - type RangeFut<'f, Q, R> = <&'ro_me T as MapApiRO<'ro_d, K>>::RangeFut<'f, Q, R> + type RangeFut<'f, Q, R> = <&'ro_me T as MapApiRO>::RangeFut<'f, Q, R> where Self: 'f, 'ro_me: 'f, - 'ro_d: 'f, K: Borrow, R: RangeBounds + Send + Sync + Clone, R: 'f, @@ -201,7 +196,6 @@ where fn range<'f, Q, R>(self, range: R) -> Self::RangeFut<'f, Q, R> where 'ro_me: 'f, - 'ro_d: 'f, K: Borrow, Q: Ord + Send + Sync + ?Sized, R: RangeBounds + Clone + Send + Sync, diff --git a/src/meta/raft-store/src/sm_v002/leveled_store/static_leveled_map.rs b/src/meta/raft-store/src/sm_v002/leveled_store/static_leveled_map.rs index 5fa35e57e1549..ce110d19c6538 100644 --- a/src/meta/raft-store/src/sm_v002/leveled_store/static_leveled_map.rs +++ b/src/meta/raft-store/src/sm_v002/leveled_store/static_leveled_map.rs @@ -62,22 +62,20 @@ impl StaticLeveledMap { } } -impl<'d, K> MapApiRO<'d, K> for &'d StaticLeveledMap +impl<'d, K> MapApiRO for &'d StaticLeveledMap where K: MapKey, - for<'him> &'him LevelData: MapApiRO<'him, K>, + for<'him> &'him LevelData: MapApiRO, { type GetFut<'f, Q> = impl Future> + 'f where Self: 'f, - 'd: 'f, K: Borrow, Q: Ord + Send + Sync + ?Sized, Q: 'f; fn get<'f, Q>(self, key: &'f Q) -> Self::GetFut<'f, Q> where - 'd: 'f, K: Borrow, Q: Ord + Send + Sync + ?Sized, Q: 'f,