Skip to content

Commit 1dd6ea9

Browse files
authored
chore: rename EvalExpireTime to Expirable for better semantics (#17540)
* rename InternalSeq to SeqTombstone * chore: rename `EvalExpireTime` to `Expirable` for better semantics This change renames the `EvalExpireTime` trait to `Expirable` and its method `eval_expire_at_ms()` to `expiry_ms()` for improved clarity and consistency.
1 parent 3c4580a commit 1dd6ea9

File tree

10 files changed

+50
-48
lines changed

10 files changed

+50
-48
lines changed

src/meta/raft-store/src/leveled_store/leveled_map/map_api_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ where
8181
let prev = self.get(&key).await?.clone();
8282

8383
// No such entry at all, no need to create a tombstone for delete
84-
if prev.not_found() && value.is_none() {
84+
if prev.is_not_found() && value.is_none() {
8585
return Ok((prev, Marked::new_tombstone(0)));
8686
}
8787

src/meta/raft-store/src/leveled_store/map_api.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub trait MapKeyEncode {
4343
///
4444
/// It is `Clone` to let MapApi clone a range of key.
4545
/// It is `Unpin` to let MapApi extract a key from pinned data, such as a stream.
46-
/// And it only accepts `'static` value for simplicity.
46+
/// And it only accepts `static` value for simplicity.
4747
pub trait MapKey: MapKeyEncode + Clone + Ord + fmt::Debug + Send + Sync + Unpin + 'static {
4848
type V: MapValue;
4949

@@ -54,10 +54,10 @@ pub trait MapKey: MapKeyEncode + Clone + Ord + fmt::Debug + Send + Sync + Unpin
5454
///
5555
/// It is `Clone` to let MapApi return an owned value.
5656
/// It is `Unpin` to let MapApi extract a value from pinned data, such as a stream.
57-
/// And it only accepts `'static` value for simplicity.
57+
/// And it only accepts `static` value for simplicity.
5858
pub trait MapValue: Clone + Send + Sync + Unpin + 'static {}
5959

60-
/// A Marked value type of a key type.
60+
/// A Marked value type of key type.
6161
pub(crate) type MarkedOf<K> = Marked<<K as MapKey>::V>;
6262

6363
/// A key-value pair used in a map.
@@ -210,6 +210,10 @@ impl MapApiExt {
210210
/// Returns the first non-tombstone entry.
211211
///
212212
/// `persisted` is a series of persisted on disk levels.
213+
///
214+
/// - `K`: key type used in a map.
215+
/// - `L`: type of the several top levels
216+
/// - `PL`: the bottom persistent level.
213217
pub(crate) async fn compacted_get<'d, K, Q, L, PL>(
214218
key: &Q,
215219
levels: impl IntoIterator<Item = &'d L>,
@@ -225,14 +229,14 @@ where
225229
{
226230
for lvl in levels {
227231
let got = lvl.get(key).await?;
228-
if !got.not_found() {
232+
if !got.is_not_found() {
229233
return Ok(got);
230234
}
231235
}
232236

233237
for p in persisted {
234238
let got = p.get(key).await?;
235-
if !got.not_found() {
239+
if !got.is_not_found() {
236240
return Ok(got);
237241
}
238242
}

src/meta/raft-store/src/marked/marked_test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use databend_common_meta_types::seq_value::KVMeta;
1616
use databend_common_meta_types::seq_value::SeqV;
1717
use databend_common_meta_types::seq_value::SeqValue;
1818

19-
use crate::marked::InternalSeq;
2019
use crate::marked::Marked;
20+
use crate::marked::SeqTombstone;
2121
use crate::state_machine::ExpireValue;
2222

2323
#[test]
@@ -62,10 +62,10 @@ fn test_empty() -> anyhow::Result<()> {
6262
#[test]
6363
fn test_order_key() -> anyhow::Result<()> {
6464
let m = Marked::new_with_meta(1, 2, None);
65-
assert_eq!(m.order_key(), InternalSeq::normal(1));
65+
assert_eq!(m.order_key(), SeqTombstone::normal(1));
6666

6767
let m: Marked<u64> = Marked::new_tombstone(1);
68-
assert_eq!(m.order_key(), InternalSeq::tombstone(1));
68+
assert_eq!(m.order_key(), SeqTombstone::tombstone(1));
6969

7070
Ok(())
7171
}

src/meta/raft-store/src/marked/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
#[cfg(test)]
1616
mod marked_test;
1717

18-
mod internal_seq;
18+
mod seq_tombstone;
1919

2020
mod marked_impl;
2121

2222
use databend_common_meta_types::seq_value::KVMeta;
2323
use databend_common_meta_types::seq_value::SeqV;
2424
use databend_common_meta_types::seq_value::SeqValue;
25-
pub(crate) use internal_seq::InternalSeq;
25+
pub(crate) use seq_tombstone::SeqTombstone;
2626

2727
use crate::state_machine::ExpireValue;
2828

@@ -108,12 +108,12 @@ impl<T> Marked<T> {
108108
}
109109

110110
/// Return a key to determine which one of the values of the same key are the last inserted.
111-
pub(crate) fn order_key(&self) -> InternalSeq {
111+
pub(crate) fn order_key(&self) -> SeqTombstone {
112112
match self {
113-
Marked::TombStone { internal_seq: seq } => InternalSeq::tombstone(*seq),
113+
Marked::TombStone { internal_seq: seq } => SeqTombstone::tombstone(*seq),
114114
Marked::Normal {
115115
internal_seq: seq, ..
116-
} => InternalSeq::normal(*seq),
116+
} => SeqTombstone::normal(*seq),
117117
}
118118
}
119119

@@ -199,7 +199,7 @@ impl<T> Marked<T> {
199199
}
200200

201201
/// Return if the entry is neither a normal entry nor a tombstone.
202-
pub fn not_found(&self) -> bool {
202+
pub fn is_not_found(&self) -> bool {
203203
matches!(self, Marked::TombStone { internal_seq: 0 })
204204
}
205205

src/meta/raft-store/src/marked/internal_seq.rs renamed to src/meta/raft-store/src/marked/seq_tombstone.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828
///
2929
/// With such a design, the system seq increases only when a new normal record is inserted, ensuring compatibility.
3030
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
31-
pub(crate) struct InternalSeq {
31+
pub(crate) struct SeqTombstone {
3232
pub(crate) seq: u64,
3333
pub(crate) tombstone: bool,
3434
}
3535

36-
impl InternalSeq {
36+
impl SeqTombstone {
3737
pub fn normal(seq: u64) -> Self {
3838
Self {
3939
seq,
@@ -59,16 +59,16 @@ impl InternalSeq {
5959

6060
#[cfg(test)]
6161
mod tests {
62-
use super::InternalSeq;
62+
use super::SeqTombstone;
6363

6464
#[test]
6565
fn test_ord() -> Result<(), anyhow::Error> {
66-
assert!(InternalSeq::normal(5) < InternalSeq::normal(6));
67-
assert!(InternalSeq::normal(7) > InternalSeq::normal(6));
68-
assert!(InternalSeq::normal(6) == InternalSeq::normal(6));
66+
assert!(SeqTombstone::normal(5) < SeqTombstone::normal(6));
67+
assert!(SeqTombstone::normal(7) > SeqTombstone::normal(6));
68+
assert!(SeqTombstone::normal(6) == SeqTombstone::normal(6));
6969

70-
assert!(InternalSeq::normal(6) < InternalSeq::tombstone(6));
71-
assert!(InternalSeq::normal(6) > InternalSeq::tombstone(5));
70+
assert!(SeqTombstone::normal(6) < SeqTombstone::tombstone(6));
71+
assert!(SeqTombstone::normal(6) > SeqTombstone::tombstone(5));
7272

7373
Ok(())
7474
}

src/meta/raft-store/src/state_machine_api_ext.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::io;
1717
use std::ops::RangeBounds;
1818

1919
use databend_common_meta_types::CmdContext;
20-
use databend_common_meta_types::EvalExpireTime;
20+
use databend_common_meta_types::Expirable;
2121
use databend_common_meta_types::MatchSeqExt;
2222
use databend_common_meta_types::Operation;
2323
use databend_common_meta_types::SeqV;
@@ -69,7 +69,7 @@ pub trait StateMachineApiExt: StateMachineApi {
6969
}
7070
};
7171

72-
let expire_ms = kv_meta.eval_expire_at_ms();
72+
let expire_ms = kv_meta.expiry_ms();
7373
if expire_ms < self.get_expire_cursor().time_ms {
7474
// The record has expired, delete it at once.
7575
//

src/meta/types/src/eval_expire_time.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,26 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
/// Evaluate and returns the absolute expire time.
16-
pub trait EvalExpireTime {
17-
/// Evaluate and returns the absolute expire time in millisecond since 1970.
15+
/// A trait for evaluating and returning the absolute expiration time.
16+
pub trait Expirable {
17+
/// Evaluates and returns the absolute expiration time in milliseconds since the Unix epoch (January 1, 1970).
1818
///
19-
/// If there is no expire time, return u64::MAX.
20-
fn eval_expire_at_ms(&self) -> u64;
19+
/// If there is no expiration time, it returns `u64::MAX`.
20+
fn expiry_ms(&self) -> u64;
2121
}
2222

23-
impl<T> EvalExpireTime for &T
24-
where T: EvalExpireTime
23+
impl<T> Expirable for &T
24+
where T: Expirable
2525
{
26-
fn eval_expire_at_ms(&self) -> u64 {
27-
EvalExpireTime::eval_expire_at_ms(*self)
26+
fn expiry_ms(&self) -> u64 {
27+
Expirable::expiry_ms(*self)
2828
}
2929
}
3030

31-
impl<T> EvalExpireTime for Option<T>
32-
where T: EvalExpireTime
31+
impl<T> Expirable for Option<T>
32+
where T: Expirable
3333
{
34-
fn eval_expire_at_ms(&self) -> u64 {
35-
self.as_ref()
36-
.map(|m| m.eval_expire_at_ms())
37-
.unwrap_or(u64::MAX)
34+
fn expiry_ms(&self) -> u64 {
35+
self.as_ref().map(|m| m.expiry_ms()).unwrap_or(u64::MAX)
3836
}
3937
}

src/meta/types/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ pub use errors::meta_network_errors::MetaNetworkError;
8080
pub use errors::meta_network_errors::MetaNetworkResult;
8181
pub use errors::meta_startup_errors::MetaStartupError;
8282
pub use errors::rpc_errors::ForwardRPCError;
83-
pub use eval_expire_time::EvalExpireTime;
83+
pub use eval_expire_time::Expirable;
8484
pub use grpc_config::GrpcConfig;
8585
pub use log_entry::LogEntry;
8686
pub use match_seq::MatchSeq;

src/meta/types/src/seq_value/kv_meta.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use serde::Deserialize;
1616
use serde::Serialize;
1717

18-
use crate::EvalExpireTime;
18+
use crate::Expirable;
1919

2020
/// The meta data of a record in kv
2121
#[derive(Serialize, Deserialize, Debug, Default, Clone, Eq, PartialEq)]
@@ -43,8 +43,8 @@ impl KVMeta {
4343
}
4444
}
4545

46-
impl EvalExpireTime for KVMeta {
47-
fn eval_expire_at_ms(&self) -> u64 {
46+
impl Expirable for KVMeta {
47+
fn expiry_ms(&self) -> u64 {
4848
match self.expire_at {
4949
None => u64::MAX,
5050
Some(exp_at_sec) => exp_at_sec * 1000,

src/meta/types/src/seq_value/seq_value_trait.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
use crate::seq_value::kv_meta::KVMeta;
16-
use crate::EvalExpireTime;
16+
use crate::Expirable;
1717

1818
pub trait SeqValue<V = Vec<u8>> {
1919
fn seq(&self) -> u64;
@@ -36,12 +36,12 @@ pub trait SeqValue<V = Vec<u8>> {
3636
}
3737

3838
/// Evaluate and returns the absolute expire time in millisecond since 1970.
39-
fn eval_expire_at_ms(&self) -> u64 {
40-
self.meta().eval_expire_at_ms()
39+
fn expiry_ms(&self) -> u64 {
40+
self.meta().expiry_ms()
4141
}
4242

4343
/// Return true if the record is expired.
4444
fn is_expired(&self, now_ms: u64) -> bool {
45-
self.eval_expire_at_ms() < now_ms
45+
self.expiry_ms() < now_ms
4646
}
4747
}

0 commit comments

Comments
 (0)