Skip to content

Commit

Permalink
build(dep): Bump governor from 0.5.1 to 0.6.0 (#3761)
Browse files Browse the repository at this point in the history
  • Loading branch information
G-XD authored Dec 16, 2023
1 parent 00b5a16 commit 6980cd1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 57 deletions.
39 changes: 4 additions & 35 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ foundationdb = { version = "0.8.0", features = [
"embedded-fdb-include",
], optional = true }
futures = { version = "0.3", default-features = false, features = ["std"] }
governor = { version = "0.5", optional = true, features = ["std"] }
governor = { version = "0.6.0", optional = true, features = ["std"] }
hdrs = { version = "0.3.0", optional = true, features = ["async_file"] }
hrana-client-proto = { version = "0.2.1", optional = true }
http = "0.2.9"
Expand Down
37 changes: 16 additions & 21 deletions core/src/layers/throttle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ use governor::clock::DefaultClock;
use governor::middleware::NoOpMiddleware;
use governor::state::InMemoryState;
use governor::state::NotKeyed;
use governor::NegativeMultiDecision;
use governor::Quota;
use governor::RateLimiter;

Expand Down Expand Up @@ -221,24 +220,22 @@ impl<R: oio::Write> oio::Write for ThrottleWrapper<R> {

loop {
match self.limiter.check_n(buf_length) {
Ok(_) => return self.inner.poll_write(cx, bs),
Err(negative) => match negative {
Ok(res) => match res {
Ok(_) => return self.inner.poll_write(cx, bs),
// the query is valid but the Decider can not accommodate them.
NegativeMultiDecision::BatchNonConforming(_, not_until) => {
Err(not_until) => {
let _ = not_until.wait_time_from(DefaultClock::default().now());
// TODO: Should lock the limiter and wait for the wait_time, or should let other small requests go first?

// FIXME: we should sleep here.
// tokio::time::sleep(wait_time).await;
}
// the query was invalid as the rate limit parameters can "never" accommodate the number of cells queried for.
NegativeMultiDecision::InsufficientCapacity(_) => {
return Poll::Ready(Err(Error::new(
ErrorKind::RateLimited,
"InsufficientCapacity due to burst size being smaller than the request size",
)))
}
},
// the query was invalid as the rate limit parameters can "never" accommodate the number of cells queried for.
Err(_) => return Poll::Ready(Err(Error::new(
ErrorKind::RateLimited,
"InsufficientCapacity due to burst size being smaller than the request size",
))),
}
}
}
Expand All @@ -258,21 +255,19 @@ impl<R: oio::BlockingWrite> oio::BlockingWrite for ThrottleWrapper<R> {

loop {
match self.limiter.check_n(buf_length) {
Ok(_) => return self.inner.write(bs),
Err(negative) => match negative {
Ok(res) => match res {
Ok(_) => return self.inner.write(bs),
// the query is valid but the Decider can not accommodate them.
NegativeMultiDecision::BatchNonConforming(_, not_until) => {
Err(not_until) => {
let wait_time = not_until.wait_time_from(DefaultClock::default().now());
thread::sleep(wait_time);
}
// the query was invalid as the rate limit parameters can "never" accommodate the number of cells queried for.
NegativeMultiDecision::InsufficientCapacity(_) => {
return Err(Error::new(
ErrorKind::RateLimited,
"InsufficientCapacity due to burst size being smaller than the request size",
))
}
},
// the query was invalid as the rate limit parameters can "never" accommodate the number of cells queried for.
Err(_) => return Err(Error::new(
ErrorKind::RateLimited,
"InsufficientCapacity due to burst size being smaller than the request size",
)),
}
}
}
Expand Down

0 comments on commit 6980cd1

Please sign in to comment.