Unverified Commit 0b46b951 authored by Byron Hsu's avatar Byron Hsu Committed by GitHub
Browse files

Fix rust warning (#2208)

parent 2763c0a7
...@@ -2,12 +2,10 @@ use crate::tree::Tree; ...@@ -2,12 +2,10 @@ use crate::tree::Tree;
use actix_web::http::header::{HeaderValue, CONTENT_TYPE}; use actix_web::http::header::{HeaderValue, CONTENT_TYPE};
use actix_web::{HttpRequest, HttpResponse}; use actix_web::{HttpRequest, HttpResponse};
use bytes::Bytes; use bytes::Bytes;
use futures_util::{Stream, StreamExt, TryStreamExt}; use futures_util::{StreamExt, TryStreamExt};
use log::{debug, info}; use log::{debug, info};
use std::collections::HashMap; use std::collections::HashMap;
use std::fmt::Debug; use std::fmt::Debug;
use std::hash::Hash;
use std::pin::Pin;
use std::sync::atomic::AtomicUsize; use std::sync::atomic::AtomicUsize;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use std::thread; use std::thread;
...@@ -252,7 +250,7 @@ impl Router { ...@@ -252,7 +250,7 @@ impl Router {
} => { } => {
// TODO: delay scheduling if cache hit rate is high because it may cause imbalance. prioritize low hit rate ones // TODO: delay scheduling if cache hit rate is high because it may cause imbalance. prioritize low hit rate ones
let mut tree = tree.lock().unwrap(); let tree = tree.lock().unwrap();
let mut running_queue = running_queue.lock().unwrap(); let mut running_queue = running_queue.lock().unwrap();
// Get current load statistics // Get current load statistics
......
...@@ -3,7 +3,7 @@ use crate::router::Router; ...@@ -3,7 +3,7 @@ use crate::router::Router;
use actix_web::{get, post, web, App, HttpRequest, HttpResponse, HttpServer, Responder}; use actix_web::{get, post, web, App, HttpRequest, HttpResponse, HttpServer, Responder};
use bytes::Bytes; use bytes::Bytes;
use env_logger::Builder; use env_logger::Builder;
use log::{debug, info, LevelFilter}; use log::{info, LevelFilter};
use std::io::Write; use std::io::Write;
#[derive(Debug)] #[derive(Debug)]
......
use dashmap::mapref::entry::Entry; use dashmap::mapref::entry::Entry;
use dashmap::DashMap; use dashmap::DashMap;
use log::info; use log::info;
use rand::distributions::{Alphanumeric, DistString};
use rand::thread_rng;
use std::cmp::min;
use std::cmp::Reverse; use std::cmp::Reverse;
use std::collections::BinaryHeap; use std::collections::BinaryHeap;
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::Arc; use std::sync::Arc;
use std::sync::RwLock; use std::sync::RwLock;
use std::thread;
use std::time::Duration; use std::time::Duration;
use std::time::{SystemTime, UNIX_EPOCH}; use std::time::{SystemTime, UNIX_EPOCH};
...@@ -248,6 +246,7 @@ impl Tree { ...@@ -248,6 +246,7 @@ impl Tree {
} }
} }
#[allow(unused_assignments)]
pub fn prefix_match(&self, text: &str) -> (String, String) { pub fn prefix_match(&self, text: &str) -> (String, String) {
let mut curr = Arc::clone(&self.root); let mut curr = Arc::clone(&self.root);
let mut curr_idx = 0; let mut curr_idx = 0;
...@@ -317,6 +316,7 @@ impl Tree { ...@@ -317,6 +316,7 @@ impl Tree {
(ret_text, tenant) (ret_text, tenant)
} }
#[allow(unused_assignments)]
pub fn prefix_match_tenant(&self, text: &str, tenant: &str) -> String { pub fn prefix_match_tenant(&self, text: &str, tenant: &str) -> String {
let mut curr = Arc::clone(&self.root); let mut curr = Arc::clone(&self.root);
let mut curr_idx = 0; let mut curr_idx = 0;
...@@ -632,9 +632,12 @@ impl Tree { ...@@ -632,9 +632,12 @@ impl Tree {
// Unit tests // Unit tests
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::time::Instant; use rand::distributions::Alphanumeric;
use rand::distributions::DistString;
use rand::thread_rng;
use rand::Rng; use rand::Rng;
use std::thread;
use std::time::Instant;
use super::*; use super::*;
...@@ -1026,7 +1029,7 @@ mod tests { ...@@ -1026,7 +1029,7 @@ mod tests {
let text = prefix[i]; let text = prefix[i];
let handle = thread::spawn(move || { let handle = thread::spawn(move || {
let (matched_text, matched_tenant) = tree_clone.prefix_match(text); let (_matched_text, _matched_tenant) = tree_clone.prefix_match(text);
}); });
handles.push(handle); handles.push(handle);
...@@ -1169,7 +1172,7 @@ mod tests { ...@@ -1169,7 +1172,7 @@ mod tests {
let prefixes = vec!["aqwefcisdf", "iajsdfkmade", "kjnzxcvewqe", "iejksduqasd"]; let prefixes = vec!["aqwefcisdf", "iajsdfkmade", "kjnzxcvewqe", "iejksduqasd"];
// Insert strings with shared prefixes // Insert strings with shared prefixes
for i in 0..100 { for _i in 0..100 {
for (j, prefix) in prefixes.iter().enumerate() { for (j, prefix) in prefixes.iter().enumerate() {
let random_suffix = random_string(10); let random_suffix = random_string(10);
let text = format!("{}{}", prefix, random_suffix); let text = format!("{}{}", prefix, random_suffix);
...@@ -1234,7 +1237,7 @@ mod tests { ...@@ -1234,7 +1237,7 @@ mod tests {
// Perform match operation // Perform match operation
let random_len = rng.gen_range(3..10); let random_len = rng.gen_range(3..10);
let search_str = format!("{}{}", prefix, random_string(random_len)); let search_str = format!("{}{}", prefix, random_string(random_len));
let (matched, _) = tree.prefix_match(&search_str); let (_matched, _) = tree.prefix_match(&search_str);
} else { } else {
// Perform insert operation // Perform insert operation
let random_len = rng.gen_range(5..15); let random_len = rng.gen_range(5..15);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment