mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 16:57:49 +03:00
mononoke: add repoid to BlobRepo
Summary: Changests store requires it in it's api methods. Let's pass repoid from configs Reviewed By: farnz Differential Revision: D7043830 fbshipit-source-id: e4e4d5852d0ca8488cabe2140555508c143ab8df
This commit is contained in:
parent
f88f3fbb21
commit
9beeaeadc5
@ -31,10 +31,10 @@ use memblob::EagerMemblob;
|
||||
use membookmarks::MemBookmarks;
|
||||
use memheads::MemHeads;
|
||||
use memlinknodes::MemLinknodes;
|
||||
use mercurial_types::{Blob, BlobNode, Changeset, Entry, MPath, Manifest, NodeHash, Parents,
|
||||
RepoPath};
|
||||
use mercurial_types::{Blob, BlobNode, Changeset, ChangesetId, Entry, MPath, Manifest, NodeHash,
|
||||
Parents, RepoPath, RepositoryId};
|
||||
use mercurial_types::manifest;
|
||||
use mercurial_types::nodehash::{ChangesetId, ManifestId};
|
||||
use mercurial_types::nodehash::ManifestId;
|
||||
use rocksblob::Rocksblob;
|
||||
use storage_types::Version;
|
||||
use tokio_core::reactor::Remote;
|
||||
@ -51,6 +51,7 @@ pub struct BlobRepo {
|
||||
heads: Arc<Heads>,
|
||||
linknodes: Arc<Linknodes>,
|
||||
changesets: Arc<Changesets>,
|
||||
repoid: RepositoryId,
|
||||
}
|
||||
|
||||
impl BlobRepo {
|
||||
@ -60,6 +61,7 @@ impl BlobRepo {
|
||||
blobstore: Arc<Blobstore>,
|
||||
linknodes: Arc<Linknodes>,
|
||||
changesets: Arc<Changesets>,
|
||||
repoid: RepositoryId,
|
||||
) -> Self {
|
||||
BlobRepo {
|
||||
heads,
|
||||
@ -67,10 +69,11 @@ impl BlobRepo {
|
||||
blobstore,
|
||||
linknodes,
|
||||
changesets,
|
||||
repoid,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_files(path: &Path) -> Result<Self> {
|
||||
pub fn new_files(path: &Path, repoid: RepositoryId) -> Result<Self> {
|
||||
let heads = FileHeads::open(path.join("heads"))
|
||||
.context(ErrorKind::StateOpen(StateOpenError::Heads))?;
|
||||
let bookmarks = FileBookmarks::open(path.join("books"))
|
||||
@ -88,10 +91,11 @@ impl BlobRepo {
|
||||
Arc::new(blobstore),
|
||||
Arc::new(linknodes),
|
||||
Arc::new(changesets),
|
||||
repoid,
|
||||
))
|
||||
}
|
||||
|
||||
pub fn new_rocksdb(path: &Path) -> Result<Self> {
|
||||
pub fn new_rocksdb(path: &Path, repoid: RepositoryId) -> Result<Self> {
|
||||
let heads = FileHeads::open(path.join("heads"))
|
||||
.context(ErrorKind::StateOpen(StateOpenError::Heads))?;
|
||||
let bookmarks = FileBookmarks::open(path.join("books"))
|
||||
@ -109,6 +113,7 @@ impl BlobRepo {
|
||||
Arc::new(blobstore),
|
||||
Arc::new(linknodes),
|
||||
Arc::new(changesets),
|
||||
repoid,
|
||||
))
|
||||
}
|
||||
|
||||
@ -118,6 +123,7 @@ impl BlobRepo {
|
||||
blobstore: EagerMemblob,
|
||||
linknodes: MemLinknodes,
|
||||
changesets: SqliteChangesets,
|
||||
repoid: RepositoryId,
|
||||
) -> Self {
|
||||
Self::new(
|
||||
Arc::new(heads),
|
||||
@ -125,10 +131,15 @@ impl BlobRepo {
|
||||
Arc::new(blobstore),
|
||||
Arc::new(linknodes),
|
||||
Arc::new(changesets),
|
||||
repoid,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn new_test_manifold<T: ToString>(bucket: T, remote: &Remote) -> Result<Self> {
|
||||
pub fn new_test_manifold<T: ToString>(
|
||||
bucket: T,
|
||||
remote: &Remote,
|
||||
repoid: RepositoryId,
|
||||
) -> Result<Self> {
|
||||
let heads = MemHeads::new();
|
||||
let bookmarks = MemBookmarks::new();
|
||||
let blobstore = ManifoldBlob::new_may_panic(bucket.to_string(), remote);
|
||||
@ -141,6 +152,7 @@ impl BlobRepo {
|
||||
Arc::new(blobstore),
|
||||
Arc::new(linknodes),
|
||||
Arc::new(changesets),
|
||||
repoid,
|
||||
))
|
||||
}
|
||||
|
||||
@ -299,6 +311,7 @@ impl Clone for BlobRepo {
|
||||
blobstore: self.blobstore.clone(),
|
||||
linknodes: self.linknodes.clone(),
|
||||
changesets: self.changesets.clone(),
|
||||
repoid: self.repoid.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,8 @@ use memblob::EagerMemblob;
|
||||
use membookmarks::MemBookmarks;
|
||||
use memheads::MemHeads;
|
||||
use memlinknodes::MemLinknodes;
|
||||
use mercurial_types::{manifest, Blob, Entry, EntryId, MPathElement, NodeHash, RepoPath};
|
||||
use mercurial_types::{manifest, Blob, Entry, EntryId, MPathElement, NodeHash, RepoPath,
|
||||
RepositoryId};
|
||||
|
||||
fn get_empty_repo() -> BlobRepo {
|
||||
let bookmarks: MemBookmarks = MemBookmarks::new();
|
||||
@ -37,8 +38,9 @@ fn get_empty_repo() -> BlobRepo {
|
||||
let blobs = EagerMemblob::new();
|
||||
let linknodes = MemLinknodes::new();
|
||||
let changesets = SqliteChangesets::in_memory().expect("cannot create in memory changesets");
|
||||
let repoid = RepositoryId::new(0);
|
||||
|
||||
BlobRepo::new_memblob(heads, bookmarks, blobs, linknodes, changesets)
|
||||
BlobRepo::new_memblob(heads, bookmarks, blobs, linknodes, changesets, repoid)
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -65,7 +65,7 @@ use futures_ext::{BoxFuture, FutureExt};
|
||||
use futures_stats::{Stats, Timed};
|
||||
use hyper::StatusCode;
|
||||
use hyper::server::{Http, Request, Response, Service};
|
||||
use mercurial_types::{Changeset, MPathElement, NodeHash};
|
||||
use mercurial_types::{Changeset, MPathElement, NodeHash, RepositoryId};
|
||||
use mercurial_types::nodehash::ChangesetId;
|
||||
use native_tls::TlsAcceptor;
|
||||
use native_tls::backend::openssl::TlsAcceptorBuilderExt;
|
||||
@ -482,6 +482,7 @@ struct RawRepoConfig {
|
||||
reponame: String,
|
||||
addr: String,
|
||||
ssl: Ssl,
|
||||
repoid: i32,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@ -520,16 +521,20 @@ fn main() {
|
||||
RawRepoType::BlobFiles => start_server(
|
||||
&config.addr,
|
||||
config.reponame,
|
||||
BlobRepo::new_files(&config.path.expect("Please specify a path to the blobrepo"))
|
||||
.expect("couldn't open blob state"),
|
||||
BlobRepo::new_files(
|
||||
&config.path.expect("Please specify a path to the blobrepo"),
|
||||
RepositoryId::new(config.repoid),
|
||||
).expect("couldn't open blob state"),
|
||||
root_logger.clone(),
|
||||
config.ssl,
|
||||
),
|
||||
RawRepoType::BlobRocks => start_server(
|
||||
&config.addr,
|
||||
config.reponame,
|
||||
BlobRepo::new_rocksdb(&config.path.expect("Please specify a path to the blobrepo"))
|
||||
.expect("couldn't open blob state"),
|
||||
BlobRepo::new_rocksdb(
|
||||
&config.path.expect("Please specify a path to the blobrepo"),
|
||||
RepositoryId::new(config.repoid),
|
||||
).expect("couldn't open blob state"),
|
||||
root_logger.clone(),
|
||||
config.ssl,
|
||||
),
|
||||
@ -558,6 +563,7 @@ fn main() {
|
||||
.manifold_bucket
|
||||
.expect("manifold bucket is not specified"),
|
||||
&remote,
|
||||
RepositoryId::new(config.repoid),
|
||||
).expect("couldn't open blob state"),
|
||||
root_logger.clone(),
|
||||
config.ssl,
|
||||
|
@ -32,6 +32,8 @@ pub struct RepoConfig {
|
||||
pub repotype: RepoType,
|
||||
/// How large a cache to use (in bytes) for RepoGenCache derived information
|
||||
pub generation_cache_size: usize,
|
||||
/// Numerical repo id of the repo.
|
||||
pub repoid: i32,
|
||||
}
|
||||
|
||||
/// Types of repositories supported
|
||||
@ -181,6 +183,7 @@ struct RawRepoConfig {
|
||||
repotype: RawRepoType,
|
||||
generation_cache_size: Option<usize>,
|
||||
manifold_bucket: Option<String>,
|
||||
repoid: i32,
|
||||
}
|
||||
|
||||
/// Types of repositories supported
|
||||
@ -211,10 +214,12 @@ impl TryFrom<RawRepoConfig> for RepoConfig {
|
||||
};
|
||||
|
||||
let generation_cache_size = this.generation_cache_size.unwrap_or(10 * 1024 * 1024);
|
||||
let repoid = this.repoid;
|
||||
|
||||
Ok(RepoConfig {
|
||||
repotype,
|
||||
generation_cache_size,
|
||||
repoid,
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -234,10 +239,12 @@ mod test {
|
||||
path="/tmp/fbsource"
|
||||
repotype="blob:files"
|
||||
generation_cache_size=1048576
|
||||
repoid=0
|
||||
"#;
|
||||
let www_content = r#"
|
||||
path="/tmp/www"
|
||||
repotype="revlog"
|
||||
repoid=1
|
||||
"#;
|
||||
|
||||
let my_path_manifest = MockManifest::with_content(vec![
|
||||
@ -269,6 +276,7 @@ mod test {
|
||||
RepoConfig {
|
||||
repotype: RepoType::BlobFiles("/tmp/fbsource".into()),
|
||||
generation_cache_size: 1024 * 1024,
|
||||
repoid: 0,
|
||||
},
|
||||
);
|
||||
repos.insert(
|
||||
@ -276,6 +284,7 @@ mod test {
|
||||
RepoConfig {
|
||||
repotype: RepoType::Revlog("/tmp/www".into()),
|
||||
generation_cache_size: 10 * 1024 * 1024,
|
||||
repoid: 1,
|
||||
},
|
||||
);
|
||||
assert_eq!(
|
||||
|
@ -77,6 +77,7 @@ use slog_logview::LogViewDrain;
|
||||
use bytes::Bytes;
|
||||
use hgproto::{sshproto, HgProtoHandler};
|
||||
use mercurial::RevlogRepo;
|
||||
use mercurial_types::RepositoryId;
|
||||
use metaconfig::RepoConfigs;
|
||||
use metaconfig::repoconfig::RepoType;
|
||||
|
||||
@ -223,7 +224,7 @@ fn get_config<'a>(logger: &Logger, matches: &ArgMatches<'a>) -> Result<RepoConfi
|
||||
|
||||
fn start_repo_listeners<I>(repos: I, root_log: &Logger) -> Result<Vec<JoinHandle<!>>>
|
||||
where
|
||||
I: IntoIterator<Item = (RepoType, usize)>,
|
||||
I: IntoIterator<Item = (RepoType, usize, i32)>,
|
||||
{
|
||||
// Given the list of paths to repos:
|
||||
// - create a thread for it
|
||||
@ -232,14 +233,21 @@ where
|
||||
|
||||
let handles: Vec<_> = repos
|
||||
.into_iter()
|
||||
.map(move |(repotype, cache_size)| {
|
||||
.map(move |(repotype, cache_size, repoid)| {
|
||||
// start a thread for each repo to own the reactor and start listening for
|
||||
// connections and detach it
|
||||
thread::Builder::new()
|
||||
.name(format!("listener_{:?}", repotype))
|
||||
.spawn({
|
||||
let root_log = root_log.clone();
|
||||
move || repo_listen(repotype, cache_size, root_log.clone())
|
||||
move || {
|
||||
repo_listen(
|
||||
repotype,
|
||||
cache_size,
|
||||
root_log.clone(),
|
||||
RepositoryId::new(repoid),
|
||||
)
|
||||
}
|
||||
})
|
||||
.map_err(Error::from)
|
||||
})
|
||||
@ -258,10 +266,11 @@ where
|
||||
}
|
||||
|
||||
// Listener thread for a specific repo
|
||||
fn repo_listen(repotype: RepoType, cache_size: usize, root_log: Logger) -> ! {
|
||||
fn repo_listen(repotype: RepoType, cache_size: usize, root_log: Logger, repoid: RepositoryId) -> ! {
|
||||
let mut core = tokio_core::reactor::Core::new().expect("failed to create tokio core");
|
||||
let (sockname, repo) = repo::init_repo(&root_log, &repotype, cache_size, &core.remote())
|
||||
.expect("failed to initialize repo");
|
||||
let (sockname, repo) =
|
||||
repo::init_repo(&root_log, &repotype, cache_size, &core.remote(), repoid)
|
||||
.expect("failed to initialize repo");
|
||||
|
||||
let listen_log = root_log.new(o!("repo" => repo.path().clone()));
|
||||
|
||||
@ -355,7 +364,7 @@ fn main() {
|
||||
config
|
||||
.repos
|
||||
.into_iter()
|
||||
.map(|(_, c)| (c.repotype, c.generation_cache_size)),
|
||||
.map(|(_, c)| (c.repotype, c.generation_cache_size, c.repoid)),
|
||||
root_log,
|
||||
)?;
|
||||
|
||||
|
@ -28,7 +28,7 @@ use bundle2_resolver;
|
||||
use mercurial;
|
||||
use mercurial_bundles::{parts, Bundle2EncodeBuilder, Bundle2Item};
|
||||
use mercurial_types::{percent_encode, BlobNode, Changeset, ChangesetId, Entry, MPath, ManifestId,
|
||||
NodeHash, Parents, RepoPath, Type, NULL_HASH};
|
||||
NodeHash, Parents, RepoPath, RepositoryId, Type, NULL_HASH};
|
||||
use mercurial_types::manifest_utils::{changed_entry_stream, EntryStatus};
|
||||
use metaconfig::repoconfig::RepoType;
|
||||
|
||||
@ -50,12 +50,13 @@ pub fn init_repo(
|
||||
repotype: &RepoType,
|
||||
cache_size: usize,
|
||||
remote: &Remote,
|
||||
repoid: RepositoryId,
|
||||
) -> Result<(PathBuf, HgRepo)> {
|
||||
let repopath = repotype.path();
|
||||
|
||||
let mut sock = repopath.join(".hg");
|
||||
|
||||
let repo = HgRepo::new(parent_logger, repotype, cache_size, remote)
|
||||
let repo = HgRepo::new(parent_logger, repotype, cache_size, remote, repoid)
|
||||
.with_context(|_| format!("Failed to initialize repo {:?}", repopath))?;
|
||||
|
||||
sock.push("mononoke.sock");
|
||||
@ -64,20 +65,20 @@ pub fn init_repo(
|
||||
}
|
||||
|
||||
pub trait OpenableRepoType {
|
||||
fn open(&self, remote: &Remote) -> Result<BlobRepo>;
|
||||
fn open(&self, remote: &Remote, repoid: RepositoryId) -> Result<BlobRepo>;
|
||||
fn path(&self) -> &Path;
|
||||
}
|
||||
|
||||
impl OpenableRepoType for RepoType {
|
||||
fn open(&self, remote: &Remote) -> Result<BlobRepo> {
|
||||
fn open(&self, remote: &Remote, repoid: RepositoryId) -> Result<BlobRepo> {
|
||||
use hgproto::ErrorKind;
|
||||
use metaconfig::repoconfig::RepoType::*;
|
||||
|
||||
let ret = match *self {
|
||||
Revlog(_) => Err(ErrorKind::CantServeRevlogRepo)?,
|
||||
BlobFiles(ref path) => BlobRepo::new_files(&path)?,
|
||||
BlobRocks(ref path) => BlobRepo::new_rocksdb(&path)?,
|
||||
TestBlobManifold(ref bucket, _) => BlobRepo::new_test_manifold(bucket, remote)?,
|
||||
BlobFiles(ref path) => BlobRepo::new_files(&path, repoid)?,
|
||||
BlobRocks(ref path) => BlobRepo::new_rocksdb(&path, repoid)?,
|
||||
TestBlobManifold(ref bucket, _) => BlobRepo::new_test_manifold(bucket, remote, repoid)?,
|
||||
};
|
||||
|
||||
Ok(ret)
|
||||
@ -141,12 +142,13 @@ impl HgRepo {
|
||||
repo: &RepoType,
|
||||
cache_size: usize,
|
||||
remote: &Remote,
|
||||
repoid: RepositoryId,
|
||||
) -> Result<Self> {
|
||||
let path = repo.path().to_owned();
|
||||
|
||||
Ok(HgRepo {
|
||||
path: format!("{}", path.display()),
|
||||
hgrepo: Arc::new(repo.open(remote)?),
|
||||
hgrepo: Arc::new(repo.open(remote, repoid)?),
|
||||
repo_generation: RepoGenCache::new(cache_size),
|
||||
_logger: parent_logger.new(o!("repo" => format!("{}", path.display()))),
|
||||
})
|
||||
|
4
tests/fixtures/generate_memblob_repo.py
vendored
4
tests/fixtures/generate_memblob_repo.py
vendored
@ -56,7 +56,7 @@ use bytes::Bytes;
|
||||
use changesets::SqliteChangesets;
|
||||
use memblob::EagerMemblob;
|
||||
use membookmarks::MemBookmarks;
|
||||
use mercurial_types::NodeHash;
|
||||
use mercurial_types::{NodeHash, RepositoryId};
|
||||
use memheads::MemHeads;
|
||||
use memlinknodes::MemLinknodes;
|
||||
use blobrepo::BlobRepo;
|
||||
@ -102,7 +102,7 @@ pub fn getrepo() -> BlobRepo {
|
||||
)
|
||||
rs.writelines(
|
||||
"""
|
||||
BlobRepo::new_memblob(heads, bookmarks, blobs, linknodes, changesets)
|
||||
BlobRepo::new_memblob(heads, bookmarks, blobs, linknodes, changesets, RepositoryId::new(0))
|
||||
}
|
||||
"""
|
||||
)
|
||||
|
@ -46,6 +46,7 @@ EOF
|
||||
cat > repos/repo <<CONFIG
|
||||
path="$TESTTMP/repo"
|
||||
repotype="blob:files"
|
||||
repoid=0
|
||||
CONFIG
|
||||
hg add -q repos
|
||||
hg ci -ma
|
||||
|
@ -109,6 +109,7 @@ Add commit with a directory
|
||||
$ echo "path=\"$TESTTMP/blobrepo\"" >> $TESTTMP/config
|
||||
$ echo "addr='127.0.0.1:$SOCKET'" >> $TESTTMP/config
|
||||
$ echo 'repotype="blob:rocks"' >> $TESTTMP/config
|
||||
$ echo 'repoid=0' >> $TESTTMP/config
|
||||
$ echo "[ssl]" >> $TESTTMP/config
|
||||
$ echo "cert=\"$TESTDIR/edenservertest.crt\"" >> $TESTTMP/config
|
||||
$ echo "private_key=\"$TESTDIR/edenservertest.key\"" >> $TESTTMP/config
|
||||
|
Loading…
Reference in New Issue
Block a user