zstore: implement indexedlog::DefaultOpenOptions

Summary: This implements `Zstore::repair` for free.

Reviewed By: xavierd

Differential Revision: D18737910

fbshipit-source-id: 7db2032ba4722b7073e777fbad7229a801724f71
This commit is contained in:
Jun Wu 2019-12-06 19:32:54 -08:00 committed by Facebook Github Bot
parent 237a9708f6
commit d4c4ccde40
2 changed files with 15 additions and 9 deletions

View File

@ -12,3 +12,4 @@ mod zstore;
pub use crate::zstore::{sha1, Id20, Zstore}; pub use crate::zstore::{sha1, Id20, Zstore};
pub use errors::{Error, Result}; pub use errors::{Error, Result};
pub use indexedlog::Repair;

View File

@ -11,7 +11,7 @@
use crypto::digest::Digest; use crypto::digest::Digest;
use crypto::sha1::Sha1; use crypto::sha1::Sha1;
use indexedlog::log as ilog; use indexedlog::{log as ilog, DefaultOpenOptions};
use lazy_static::lazy_static; use lazy_static::lazy_static;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::borrow::Cow; use std::borrow::Cow;
@ -35,13 +35,9 @@ pub struct Zstore {
pub delta_opts: DeltaOptions, pub delta_opts: DeltaOptions,
} }
impl Zstore { impl DefaultOpenOptions<ilog::OpenOptions> for Zstore {
const ID20_INDEX: usize = 0; fn default_open_options() -> ilog::OpenOptions {
ilog::OpenOptions::new()
/// Load or create [Zstore] at the given directory.
pub fn open(dir: impl AsRef<Path>) -> crate::Result<Zstore> {
let dir = dir.as_ref();
let log = ilog::OpenOptions::new()
.index("id", |_| -> Vec<_> { .index("id", |_| -> Vec<_> {
// The offset of `start` should match mincode serialization layout // The offset of `start` should match mincode serialization layout
// of `Delta`. // of `Delta`.
@ -61,7 +57,16 @@ impl Zstore {
} }
Ok(ilog::FlushFilterOutput::Keep) Ok(ilog::FlushFilterOutput::Keep)
})) }))
.open(dir)?; }
}
impl Zstore {
const ID20_INDEX: usize = 0;
/// Load or create [Zstore] at the given directory.
pub fn open(dir: impl AsRef<Path>) -> crate::Result<Zstore> {
let dir = dir.as_ref();
let log = Self::default_open_options().open(dir)?;
Ok(Self { Ok(Self {
dir: dir.to_path_buf(), dir: dir.to_path_buf(),
log, log,