Skip to content

Commit

Permalink
feat: introduce recover mode (#444)
Browse files Browse the repository at this point in the history
* feat: introduce recover mode

Signed-off-by: MrCroxx <mrcroxx@outlook.com>

* fix: fix recovery bugs, add uts

Signed-off-by: MrCroxx <mrcroxx@outlook.com>

* chore: update example and readme

Signed-off-by: MrCroxx <mrcroxx@outlook.com>

---------

Signed-off-by: MrCroxx <mrcroxx@outlook.com>
  • Loading branch information
MrCroxx committed Apr 28, 2024
1 parent 8d971d4 commit 44a10ef
Show file tree
Hide file tree
Showing 12 changed files with 302 additions and 42 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -87,7 +87,7 @@ use anyhow::Result;
use chrono::Datelike;
use foyer::{
CacheContext, FsDeviceConfigBuilder, HybridCache, HybridCacheBuilder, LfuConfig, LruConfig,
RatedTicketAdmissionPolicy, RatedTicketReinsertionPolicy, RuntimeConfigBuilder,
RatedTicketAdmissionPolicy, RatedTicketReinsertionPolicy, RecoverMode, RuntimeConfigBuilder,
};
use tempfile::tempdir;

Expand Down Expand Up @@ -126,6 +126,7 @@ async fn main() -> Result<()> {
.with_flushers(2)
.with_reclaimers(2)
.with_clean_region_threshold(2)
.with_recover_mode(RecoverMode::QuietRecovery)
.with_recover_concurrency(4)
.with_compression(foyer::Compression::Lz4)
.with_flush(true)
Expand Down
3 changes: 2 additions & 1 deletion examples/hybrid_full.rs
Expand Up @@ -18,7 +18,7 @@ use anyhow::Result;
use chrono::Datelike;
use foyer::{
CacheContext, FsDeviceConfigBuilder, HybridCache, HybridCacheBuilder, LfuConfig, LruConfig,
RatedTicketAdmissionPolicy, RatedTicketReinsertionPolicy, RuntimeConfigBuilder,
RatedTicketAdmissionPolicy, RatedTicketReinsertionPolicy, RecoverMode, RuntimeConfigBuilder,
};
use tempfile::tempdir;

Expand Down Expand Up @@ -57,6 +57,7 @@ async fn main() -> Result<()> {
.with_flushers(2)
.with_reclaimers(2)
.with_clean_region_threshold(2)
.with_recover_mode(RecoverMode::QuietRecovery)
.with_recover_concurrency(4)
.with_compression(foyer::Compression::Lz4)
.with_flush(false)
Expand Down
9 changes: 8 additions & 1 deletion foyer-storage/src/catalog.rs
Expand Up @@ -12,7 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::{borrow::Borrow, fmt::Debug, hash::Hash, sync::Arc, time::Instant};
use std::{
borrow::Borrow,
fmt::Debug,
hash::Hash,
sync::{atomic::AtomicU64, Arc},
time::Instant,
};

use ahash::RandomState;
use foyer_common::{
Expand All @@ -28,6 +34,7 @@ use crate::{
};

pub type Sequence = u64;
pub type AtomicSequence = AtomicU64;

#[derive(Debug)]
pub enum Index<K, V>
Expand Down
7 changes: 5 additions & 2 deletions foyer-storage/src/device/fs.rs
Expand Up @@ -164,7 +164,8 @@ impl Device for FsDevice {

assert!(
offset + len <= file_capacity,
"offset ({offset}) + len ({len}) <= file capacity ({file_capacity})"
"offset ({offset}) + len ({len}) = {} <= file capacity ({file_capacity})",
offset + len
);

let file = self.file(region).clone();
Expand Down Expand Up @@ -258,6 +259,8 @@ impl Device for FsDevice {
}

impl FsDevice {
pub const PREFIX: &'static str = "foyer-cache-";

pub async fn open(config: FsDeviceConfig) -> DeviceResult<Self> {
config.assert();

Expand Down Expand Up @@ -312,7 +315,7 @@ impl FsDevice {
}

fn filename(region: RegionId) -> String {
format!("foyer-cache-{:08}", region)
format!("{}{:08}", Self::PREFIX, region)
}
}

Expand Down

0 comments on commit 44a10ef

Please sign in to comment.