propagate error in map_region_to_store

Signed-off-by: ekexium <ekexium@gmail.com>
This commit is contained in:
ekexium 2020-09-15 10:09:44 +08:00
parent a10432a366
commit 307293acd9
1 changed files with 11 additions and 8 deletions

View File

@ -177,14 +177,17 @@ impl<KvC: KvConnect + Send + Sync + 'static> PdClient for PdRpcClient<KvC> {
region: Region, region: Region,
) -> BoxFuture<'static, Result<Store<KvC::KvClient>>> { ) -> BoxFuture<'static, Result<Store<KvC::KvClient>>> {
let timeout = self.timeout; let timeout = self.timeout;
// FIXME propagate this error instead of using `unwrap`. let store_id_res = region.get_store_id();
let store_id = region.get_store_id().unwrap(); match store_id_res {
self.pd Err(e) => future::err(e).boxed(),
.clone() Ok(store_id) => self
.get_store(store_id) .pd
.ok_and_then(move |store| self.kv_client(store.get_address())) .clone()
.map_ok(move |kv_client| Store::new(region, kv_client, timeout)) .get_store(store_id)
.boxed() .ok_and_then(move |store| self.kv_client(store.get_address()))
.map_ok(move |kv_client| Store::new(region, kv_client, timeout))
.boxed(),
}
} }
fn region_for_key(&self, key: &Key) -> BoxFuture<'static, Result<Region>> { fn region_for_key(&self, key: &Key) -> BoxFuture<'static, Result<Region>> {