mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 08:47:12 +03:00
revisionstore: use async_runtime in EdenAPI stores
Summary: Now that the `async_runtime` crate exists, use Mercurial's global `tokio::Runtime` instead of creating one for each EdenAPI store. Reviewed By: quark-zju Differential Revision: D23945569 fbshipit-source-id: 7d7ef6efbb554ca80131daeeb2467e57bbda6e72
This commit is contained in:
parent
563f866548
commit
d3b39542f0
@ -110,13 +110,13 @@ py_class!(pub class client |py| {
|
||||
|
||||
def filestore(&self, repo: String) -> PyResult<edenapifilestore> {
|
||||
let edenapi = self.extract_inner(py);
|
||||
let store = EdenApiFileStore::new(repo, edenapi).map_pyerr(py)?;
|
||||
let store = EdenApiFileStore::new(repo, edenapi);
|
||||
edenapifilestore::new(py, store)
|
||||
}
|
||||
|
||||
def treestore(&self, repo: String) -> PyResult<edenapitreestore> {
|
||||
let edenapi = self.extract_inner(py);
|
||||
let store = EdenApiTreeStore::new(repo, edenapi).map_pyerr(py)?;
|
||||
let store = EdenApiTreeStore::new(repo, edenapi);
|
||||
edenapitreestore::new(py, store)
|
||||
}
|
||||
});
|
||||
|
@ -50,8 +50,8 @@ impl BackingStore {
|
||||
Some(repo) if use_edenapi => {
|
||||
let edenapi = EdenApiBuilder::from_config(&config)?.build()?;
|
||||
let edenapi: Arc<dyn EdenApi> = Arc::new(edenapi);
|
||||
let fileremotestore = EdenApiFileStore::new(repo.clone(), edenapi.clone())?;
|
||||
let treeremotestore = EdenApiTreeStore::new(repo, edenapi)?;
|
||||
let fileremotestore = EdenApiFileStore::new(repo.clone(), edenapi.clone());
|
||||
let treeremotestore = EdenApiTreeStore::new(repo, edenapi);
|
||||
(
|
||||
blobstore.remotestore(fileremotestore).build()?,
|
||||
treestore.remotestore(treeremotestore).build()?,
|
||||
|
@ -10,6 +10,8 @@ use std::sync::Arc;
|
||||
use anyhow::Result;
|
||||
use futures::prelude::*;
|
||||
|
||||
use async_runtime::block_on_future;
|
||||
|
||||
use crate::{
|
||||
datastore::{HgIdDataStore, HgIdMutableDeltaStore, Metadata, RemoteDataStore, StoreResult},
|
||||
localstore::LocalStore,
|
||||
@ -51,8 +53,7 @@ impl RemoteDataStore for EdenApiDataStore<File> {
|
||||
self.store.get_missing(keys)
|
||||
};
|
||||
|
||||
let mut rt = self.remote.runtime.lock();
|
||||
rt.block_on(fetch)
|
||||
block_on_future(fetch)
|
||||
}
|
||||
|
||||
fn upload(&self, keys: &[StoreKey]) -> Result<Vec<StoreKey>> {
|
||||
@ -75,8 +76,7 @@ impl RemoteDataStore for EdenApiDataStore<Tree> {
|
||||
self.store.get_missing(keys)
|
||||
};
|
||||
|
||||
let mut rt = self.remote.runtime.lock();
|
||||
rt.block_on(fetch)
|
||||
block_on_future(fetch)
|
||||
}
|
||||
|
||||
fn upload(&self, keys: &[StoreKey]) -> Result<Vec<StoreKey>> {
|
||||
@ -152,8 +152,8 @@ mod tests {
|
||||
let trees = HashMap::new();
|
||||
|
||||
let client = FakeEdenApi::new().files(files).trees(trees).into_arc();
|
||||
let remote_files = EdenApiRemoteStore::<File>::new("repo", client.clone())?;
|
||||
let remote_trees = EdenApiRemoteStore::<Tree>::new("repo", client.clone())?;
|
||||
let remote_files = EdenApiRemoteStore::<File>::new("repo", client.clone());
|
||||
let remote_trees = EdenApiRemoteStore::<Tree>::new("repo", client);
|
||||
|
||||
// Set up local mutable store to write received data.
|
||||
let tmp = TempDir::new()?;
|
||||
@ -217,8 +217,8 @@ mod tests {
|
||||
let trees = hashmap! { k.clone() => d.data.clone() };
|
||||
|
||||
let client = FakeEdenApi::new().files(files).trees(trees).into_arc();
|
||||
let remote_files = EdenApiRemoteStore::<File>::new("repo", client.clone())?;
|
||||
let remote_trees = EdenApiRemoteStore::<Tree>::new("repo", client.clone())?;
|
||||
let remote_files = EdenApiRemoteStore::<File>::new("repo", client.clone());
|
||||
let remote_trees = EdenApiRemoteStore::<Tree>::new("repo", client);
|
||||
|
||||
// Set up local mutable store to write received data.
|
||||
let tmp = TempDir::new()?;
|
||||
@ -277,7 +277,7 @@ mod tests {
|
||||
fn test_missing() -> Result<()> {
|
||||
// Set up empty EdenApi remote store.
|
||||
let client = FakeEdenApi::new().into_arc();
|
||||
let remote = EdenApiRemoteStore::<File>::new("repo", client)?;
|
||||
let remote = EdenApiRemoteStore::<File>::new("repo", client);
|
||||
|
||||
// Set up local mutable store.
|
||||
let tmp = TempDir::new()?;
|
||||
|
@ -10,6 +10,7 @@ use std::sync::Arc;
|
||||
use anyhow::Result;
|
||||
use futures::prelude::*;
|
||||
|
||||
use async_runtime::block_on_future;
|
||||
use types::{Key, NodeInfo};
|
||||
|
||||
use crate::{
|
||||
@ -57,8 +58,7 @@ impl RemoteHistoryStore for EdenApiHistoryStore {
|
||||
Ok(())
|
||||
};
|
||||
|
||||
let mut rt = self.remote.runtime.lock();
|
||||
rt.block_on(fetch)
|
||||
block_on_future(fetch)
|
||||
}
|
||||
}
|
||||
|
||||
@ -107,7 +107,7 @@ mod tests {
|
||||
let history = hashmap! { k.clone() => n.clone() };
|
||||
|
||||
let client = FakeEdenApi::new().history(history).into_arc();
|
||||
let remote = EdenApiRemoteStore::<File>::new("repo", client.clone())?;
|
||||
let remote = EdenApiRemoteStore::<File>::new("repo", client);
|
||||
|
||||
// Set up local mutable store to write received data.
|
||||
let tmp = TempDir::new()?;
|
||||
@ -131,7 +131,7 @@ mod tests {
|
||||
#[should_panic]
|
||||
fn test_tree_history() {
|
||||
let client = FakeEdenApi::new().into_arc();
|
||||
let remote = EdenApiRemoteStore::<Tree>::new("repo", client.clone()).unwrap();
|
||||
let remote = EdenApiRemoteStore::<Tree>::new("repo", client);
|
||||
|
||||
// Set up local mutable store to write received data.
|
||||
let tmp = TempDir::new().unwrap();
|
||||
|
@ -8,10 +8,7 @@
|
||||
use std::marker::PhantomData;
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::Result;
|
||||
use async_trait::async_trait;
|
||||
use parking_lot::Mutex;
|
||||
use tokio::runtime::Runtime;
|
||||
|
||||
use edenapi::{EdenApi, EdenApiError, Fetch, ProgressCallback};
|
||||
use edenapi_types::{FileEntry, TreeEntry};
|
||||
@ -45,7 +42,6 @@ pub type EdenApiTreeStore = EdenApiRemoteStore<Tree>;
|
||||
pub struct EdenApiRemoteStore<T> {
|
||||
client: Arc<dyn EdenApi>,
|
||||
repo: String,
|
||||
runtime: Mutex<Runtime>,
|
||||
_phantom: PhantomData<T>,
|
||||
}
|
||||
|
||||
@ -70,13 +66,12 @@ impl<T: EdenApiStoreKind> EdenApiRemoteStore<T> {
|
||||
/// ```rust,ignore
|
||||
/// let store = EdenApiStore::<File>::new(repo, edenapi);
|
||||
/// ```
|
||||
pub fn new(repo: impl ToString, client: Arc<dyn EdenApi>) -> Result<Arc<Self>> {
|
||||
Ok(Arc::new(Self {
|
||||
pub fn new(repo: impl ToString, client: Arc<dyn EdenApi>) -> Arc<Self> {
|
||||
Arc::new(Self {
|
||||
client,
|
||||
repo: repo.to_string(),
|
||||
runtime: Mutex::new(Runtime::new()?),
|
||||
_phantom: PhantomData,
|
||||
}))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user