Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "map-api"
description = "Raft state machine"
version = "0.1.0"
version = "0.1.1"
authors = ["Databend Authors <opensource@datafuselabs.com>"]
license = "Apache-2.0"
edition = "2021"
Expand Down
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
all: test fmt clippy doc

test:
cargo test

fmt:
cargo fmt

clippy:
cargo clippy

doc:
cargo doc


2 changes: 2 additions & 0 deletions src/compact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//! Compact operations on multi levels data.

use std::io;
use std::ops::RangeBounds;

Expand Down
6 changes: 6 additions & 0 deletions src/expirable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//! Expirable trait for types that can have an expiration time.
//!
//! This module provides the `Expirable` trait which allows types to define
//! and query their expiration time in milliseconds since the Unix epoch.
//! It's used to implement time-to-live (TTL) functionality for stored values.

/// A trait for evaluating and returning the absolute expiration time.
pub trait Expirable {
/// Returns the optional expiration time in milliseconds since the Unix epoch (January 1, 1970).
Expand Down
2 changes: 2 additions & 0 deletions src/impls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//! Implementations of the `MapApi` trait for different storage backends.

pub mod immutable;
pub mod level;
6 changes: 6 additions & 0 deletions src/seq_value/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//! Sequenced values with metadata.
//!
//! This module provides traits and implementations for values that have an associated
//! sequence number and optional metadata. These are used to track the ordering and
//! lifecycle of values in storage systems.

mod seq_value_trait;
mod seqv;
mod update;
Expand Down
18 changes: 15 additions & 3 deletions src/seq_value/seq_value_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,43 @@

use crate::expirable::Expirable;

/// Trait for some value with sequence number and metadata.
pub trait SeqValue<M, V = Vec<u8>> {
/// Return the sequence number of the value.
fn seq(&self) -> u64;

/// Return the reference of the value.
fn value(&self) -> Option<&V>;

/// Consume the value and return the value.
fn into_value(self) -> Option<V>;

/// Return the reference of metadata of the value.
fn meta(&self) -> Option<&M>;

/// Consume self and return the sequence number and the value.
fn unpack(self) -> (u64, Option<V>)
where Self: Sized {
(self.seq(), self.into_value())
}

/// Return the expire time in millisecond since 1970.
/// Return the absolute expire time in millisecond since 1970-01-01 00:00:00.
fn expires_at_ms_opt(&self) -> Option<u64>
where M: Expirable {
let meta = self.meta()?;
meta.expires_at_ms_opt()
}

/// Evaluate and returns the absolute expire time in millisecond since 1970.
/// Returns the absolute expiration time in milliseconds since the Unix epoch (1970-01-01 00:00:00 UTC).
///
/// If no expiration time is set, returns `u64::MAX`, effectively meaning the value never expires.
/// This method provides a consistent way to handle both expiring and non-expiring values.
fn expires_at_ms(&self) -> u64
where M: Expirable {
self.meta().expires_at_ms()
}

/// Return true if the record is expired.
/// Return true if the record is expired at the given time in milliseconds since the Unix epoch (1970-01-01 00:00:00 UTC).
fn is_expired(&self, now_ms: u64) -> bool
where M: Expirable {
self.expires_at_ms() < now_ms
Expand Down
1 change: 1 addition & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//! Utility functions and types for the map API.
use std::fmt;
use std::io;

Expand Down
Loading