web search done right
[sonic] probagate errors from each shard independently
Mikkel Denker016f7dbfac21
diff --git a/crates/core/src/distributed/sonic/replication.rs b/crates/core/src/distributed/sonic/replication.rsindex f4c04592..7c53b6dd 100644--- a/crates/core/src/distributed/sonic/replication.rs+++ b/crates/core/src/distributed/sonic/replication.rs@@ -396,7 +396,7 @@ whereshard_selector: &SSel,replica_selector: &RSel,timeout: Duration,- ) -> Result<Vec<(Id, Vec<(SocketAddr, Req::Response)>)>>+ ) -> Result<Vec<Result<(Id, Vec<(SocketAddr, Req::Response)>)>>>whereReq: sonic::service::Wrapper<S> + Clone,SSel: ShardSelector<S, Id>,@@ -414,10 +414,10 @@ wherelet mut results = Vec::new();for r in join_all(futures).await {match r {- Ok(r) => results.push(r),+ Ok(r) => results.push(Ok(r)),Err(e) => {tracing::error!("Failed to send request: {:?}", e);- return Err(e);+ results.push(Err(e));}}}@@ -430,7 +430,7 @@ wherereq: Req,shard_selector: &SSel,replica_selector: &RSel,- ) -> Result<Vec<(Id, Vec<(SocketAddr, Req::Response)>)>>+ ) -> Result<Vec<Result<(Id, Vec<(SocketAddr, Req::Response)>)>>>whereReq: sonic::service::Wrapper<S> + Clone,SSel: ShardSelector<S, Id>,diff --git a/crates/core/src/live_index/crawler/mod.rs b/crates/core/src/live_index/crawler/mod.rsindex 1e7a302b..9747a3fb 100644--- a/crates/core/src/live_index/crawler/mod.rs+++ b/crates/core/src/live_index/crawler/mod.rs@@ -96,6 +96,12 @@ impl Client {while let Err(e) = conn.send(req.clone(), &RandomShardSelector, &RandomReplicaSelector).await+ .map_err(|e| anyhow::anyhow!("send failed: {e}"))+ .and_then(|v| {+ v.into_iter()+ .map(|v| v.map_err(|e| anyhow::anyhow!("shard failed: {e}")))+ .collect::<Result<Vec<_>>>()+ }){tracing::error!("Failed to index pages: {e}");tokio::time::sleep(Duration::from_millis(1_000)).await;diff --git a/crates/core/src/live_index/crawler/site_url_stream.rs b/crates/core/src/live_index/crawler/site_url_stream.rsindex d199327e..835aa78d 100644--- a/crates/core/src/live_index/crawler/site_url_stream.rs+++ b/crates/core/src/live_index/crawler/site_url_stream.rs@@ -68,6 +68,7 @@ impl StreamingResponse for SiteUrlStream<search_server::SearchService> {Ok(res.into_iter()+ .flatten().flat_map(|(_, v)| v.into_iter().flat_map(|(_, v)| v.urls)).collect())}@@ -90,6 +91,7 @@ impl StreamingResponse for SiteUrlStream<live_index::LiveIndexService> {Ok(res.into_iter()+ .flatten().flat_map(|(_, v)| v.into_iter().flat_map(|(_, v)| v.urls)).collect())}diff --git a/crates/core/src/searcher/distributed.rs b/crates/core/src/searcher/distributed.rsindex b3c4839b..eb9cba77 100644--- a/crates/core/src/searcher/distributed.rs+++ b/crates/core/src/searcher/distributed.rs@@ -236,6 +236,7 @@ impl DistributedSearcher {{Ok(v) => v.into_iter()+ .flatten().flat_map(|(_, v)| v.into_iter().map(|(_, v)| v)).flatten().flatten()@@ -262,7 +263,7 @@ impl SearchClient for DistributedSearcher {).await{- for (shard_id, mut res) in res {+ for (shard_id, mut res) in res.into_iter().flatten() {if let Some((_, Some(res))) = res.pop() {results.push(InitialSearchResultShard {local_result: res,@@ -329,6 +330,7 @@ impl SearchClient for DistributedSearcher {if let Some(res) = res.into_iter()+ .flatten().flat_map(|(_, v)| v.into_iter().map(|(_, v)| v)).flatten().next()@@ -355,6 +357,7 @@ impl SearchClient for DistributedSearcher {match res {Ok(v) => v.into_iter()+ .flatten().flat_map(|(_, v)| {v.into_iter().map(|(_, crate::bincode_utils::SerdeCompat(v))| v)@@ -385,7 +388,9 @@ impl SearchClient for DistributedSearcher {).await.map_err(|_| Error::SearchFailed)?- .pop()+ .into_iter()+ .flatten()+ .next().and_then(|(_, mut v)| v.pop()).and_then(|(_, v)| v))}@@ -403,7 +408,9 @@ impl SearchClient for DistributedSearcher {).await.ok()?- .pop()+ .into_iter()+ .flatten()+ .next().and_then(|(_, mut v)| v.pop()).and_then(|(_, v)| v)}@@ -424,7 +431,7 @@ impl SearchClient for DistributedSearcher {Ok(res) => {let mut phrases = HashMap::new();- for (_, v) in res {+ for (_, v) in res.into_iter().flatten() {for (_, v) in v {for phrase in v {*phrases.entry(phrase.text().to_string()).or_default() +=diff --git a/crates/core/src/searcher/live.rs b/crates/core/src/searcher/live.rsindex a138f4c3..d0670410 100644--- a/crates/core/src/searcher/live.rs+++ b/crates/core/src/searcher/live.rs@@ -103,6 +103,7 @@ impl LiveSearcher {{Ok(v) => v.into_iter()+ .flatten().flat_map(|(_, v)| v.into_iter().map(|(_, v)| v)).flatten().flatten()@@ -129,7 +130,7 @@ impl SearchClient for LiveSearcher {).await{- for (shard_id, mut res) in res {+ for (shard_id, mut res) in res.into_iter().flatten() {if let Some((_, Some(res))) = res.pop() {results.push(InitialSearchResultShard {local_result: res,diff --git a/crates/core/src/webgraph/remote.rs b/crates/core/src/webgraph/remote.rsindex 7c11c927..0d62f865 100644--- a/crates/core/src/webgraph/remote.rs+++ b/crates/core/src/webgraph/remote.rs@@ -184,6 +184,7 @@ impl<G: WebgraphGranularity> RemoteWebgraph<G> {Ok(res.into_iter()+ .flatten().flat_map(|(_, res)| res.into_iter().map(|(_, v)| v)).find(|n| n.is_some()).flatten()@@ -229,6 +230,7 @@ impl<G: WebgraphGranularity> RemoteWebgraph<G> {Ok(res.into_iter()+ .flatten().flat_map(|(_, reps)| {debug_assert!(reps.len() <= 1);reps.into_iter().flat_map(|(_, rep)| rep)@@ -249,6 +251,7 @@ impl<G: WebgraphGranularity> RemoteWebgraph<G> {Ok(res.into_iter()+ .flatten().flat_map(|(_, reps)| {debug_assert!(reps.len() <= 1);reps.into_iter().flat_map(|(_, rep)| rep)@@ -273,6 +276,7 @@ impl<G: WebgraphGranularity> RemoteWebgraph<G> {Ok(res.into_iter()+ .flatten().flat_map(|(_, reps)| {debug_assert!(reps.len() <= 1);reps.into_iter().flat_map(|(_, rep)| rep)@@ -355,6 +359,7 @@ impl<G: WebgraphGranularity> RemoteWebgraph<G> {Ok(res.into_iter()+ .flatten().flat_map(|(_, reps)| {debug_assert!(reps.len() <= 1);reps.into_iter().flat_map(|(_, rep)| rep)@@ -375,6 +380,7 @@ impl<G: WebgraphGranularity> RemoteWebgraph<G> {Ok(res.into_iter()+ .flatten().flat_map(|(_, reps)| {debug_assert!(reps.len() <= 1);reps.into_iter().flat_map(|(_, rep)| rep)@@ -399,6 +405,7 @@ impl<G: WebgraphGranularity> RemoteWebgraph<G> {Ok(res.into_iter()+ .flatten().flat_map(|(_, reps)| {debug_assert!(reps.len() <= 1);reps.into_iter().flat_map(|(_, rep)| rep)@@ -475,6 +482,7 @@ impl StreamingResponse for StreamNodeIDs {Ok(res.into_iter()+ .flatten().flat_map(|(_, v)| v.into_iter().flat_map(|(_, v)| v)).collect())}