web search done right
enable tcp linger and shutdown stream on timeout
Mikkel Denkercfdf66473e42
diff --git a/crates/core/src/ampc/dht/mod.rs b/crates/core/src/ampc/dht/mod.rsindex 13e3f5db..11fcf2e7 100644--- a/crates/core/src/ampc/dht/mod.rs+++ b/crates/core/src/ampc/dht/mod.rs@@ -255,6 +255,21 @@ pub mod tests {let res = c1.get(table.clone(), "hello".as_bytes().into()).await?;assert_eq!(res, Some("world2".as_bytes().into()));+ let res = c1.batch_get(table.clone(), vec![]).await?;+ assert!(res.is_empty());++ let res = c1+ .batch_get(table.clone(), vec!["hello".as_bytes().into()])+ .await?;++ assert!(res.len() == 1);++ let res = c1+ .batch_get(table.clone(), vec!["non-existent-key".as_bytes().into()])+ .await?;++ assert!(res.is_empty());+Ok(())}diff --git a/crates/core/src/ampc/dht/network/api.rs b/crates/core/src/ampc/dht/network/api.rsindex a6807ae3..575ef91a 100644--- a/crates/core/src/ampc/dht/network/api.rs+++ b/crates/core/src/ampc/dht/network/api.rs@@ -340,7 +340,7 @@ impl RemoteClient {key: key.clone(),value: value.clone(),},- Duration::from_secs(5),+ Duration::from_secs(60),).await;@@ -408,7 +408,7 @@ impl RemoteClient {table: table.clone(),values: values.clone(),},- Duration::from_secs(5),+ Duration::from_secs(60),).await;@@ -469,7 +469,7 @@ impl RemoteClient {NumKeys {table: table.clone(),},- Duration::from_secs(5),+ Duration::from_secs(60),).await{@@ -503,7 +503,7 @@ impl RemoteClient {table: table.clone(),key: key.clone(),},- Duration::from_secs(5),+ Duration::from_secs(60),).await{@@ -539,7 +539,7 @@ impl RemoteClient {table: table.clone(),keys: keys.clone(),},- Duration::from_secs(5),+ Duration::from_secs(60),).await{@@ -576,7 +576,7 @@ impl RemoteClient {DropTable {table: table.clone(),},- Duration::from_secs(5),+ Duration::from_secs(60),).await;@@ -641,7 +641,7 @@ impl RemoteClient {CreateTable {table: table.clone(),},- Duration::from_secs(5),+ Duration::from_secs(60),).await;@@ -702,7 +702,7 @@ impl RemoteClient {.await.as_ref().unwrap_or(&self.self_remote)- .send_with_timeout(AllTables, Duration::from_secs(5))+ .send_with_timeout(AllTables, Duration::from_secs(60)).await;match res {@@ -767,7 +767,7 @@ impl RemoteClient {from: from.clone(),to: to.clone(),},- Duration::from_secs(5),+ Duration::from_secs(60),).await;@@ -843,7 +843,7 @@ impl RemoteClient {value: value.clone(),upsert_fn: upsert.clone(),},- Duration::from_secs(5),+ Duration::from_secs(60),).await;@@ -918,7 +918,7 @@ impl RemoteClient {upsert_fn: upsert.clone(),values: values.clone(),},- Duration::from_secs(5),+ Duration::from_secs(60),).await;@@ -986,7 +986,7 @@ impl RemoteClient {range: range.clone(),limit,},- Duration::from_secs(5),+ Duration::from_secs(60),).await;diff --git a/crates/core/src/distributed/retry_strategy.rs b/crates/core/src/distributed/retry_strategy.rsindex f9df8df5..93f920ce 100644--- a/crates/core/src/distributed/retry_strategy.rs+++ b/crates/core/src/distributed/retry_strategy.rs@@ -12,7 +12,6 @@ use std::time::Duration;pub struct ExponentialBackoff {current: u64,base: u64,- factor: u64,max_delay: Option<Duration>,}@@ -26,7 +25,6 @@ impl ExponentialBackoff {ExponentialBackoff {current: base,base,- factor: 1u64,max_delay: None,}}@@ -41,12 +39,7 @@ impl Iterator for ExponentialBackoff {type Item = Duration;fn next(&mut self) -> Option<Duration> {- // set delay duration by applying factor- let duration = if let Some(duration) = self.current.checked_mul(self.factor) {- Duration::from_millis(duration)- } else {- Duration::from_millis(u64::MAX)- };+ let duration = Duration::from_millis(self.current);// check if we reached max delayif let Some(ref max_delay) = self.max_delay {@@ -55,6 +48,7 @@ impl Iterator for ExponentialBackoff {}}+ // calculate next delayif let Some(next) = self.current.checked_mul(self.base) {self.current = next;} else {diff --git a/crates/core/src/distributed/sonic/mod.rs b/crates/core/src/distributed/sonic/mod.rsindex b1c38445..32e93749 100644--- a/crates/core/src/distributed/sonic/mod.rs+++ b/crates/core/src/distributed/sonic/mod.rs@@ -118,11 +118,6 @@ whereasync fn send_without_timeout(&mut self, request: &Req) -> Result<Res> {let bytes = bincode::encode_to_vec(request, bincode::config::standard()).unwrap();- // disable linger to avoid TIME_WAIT.- // should be safe since the connection is closed from the client side.- // No stray packets should therefore find its way to the socket.- self.stream.set_linger(Some(Duration::from_secs(0)))?;-let header = Header {body_size: bytes.len(),};@@ -160,7 +155,10 @@ wherepub async fn send_with_timeout(&mut self, request: &Req, timeout: Duration) -> Result<Res> {match tokio::time::timeout(timeout, self.send_without_timeout(request)).await {Ok(res) => res,- Err(_) => Err(Error::RequestTimeout),+ Err(_) => {+ self.stream.shutdown().await?;+ Err(Error::RequestTimeout)+ }}}diff --git a/crates/core/src/webgraph/store.rs b/crates/core/src/webgraph/store.rsindex 937cfb5e..8dee58d8 100644--- a/crates/core/src/webgraph/store.rs+++ b/crates/core/src/webgraph/store.rs@@ -86,7 +86,6 @@ impl HostDb {pub fn flush(&mut self) {self.db.commit().unwrap();- self.db.merge_all_segments().unwrap();}}