mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-11-28 05:34:02 +00:00
fix(otlp): avoid waiting with body permits held
Signed-off-by: shuiyisong <xixing.sys@gmail.com>
This commit is contained in:
@@ -81,6 +81,7 @@ including caches owned by pipeline and protocol handlers.
|
||||
the exemplar destination or reserving expansion memory.
|
||||
Reserve exemplar expansion with the transport's memory limiter before building
|
||||
rows; retain the permit through `WriteProgress` until writes complete.
|
||||
Expansion must not wait while the request holds transport memory permits.
|
||||
|
||||
- **Logical-table batching** (`instance/logical_batcher.rs`): `Services` initializes
|
||||
one shared batcher for opted-in HTTP Prom and OTLP metric-engine
|
||||
|
||||
@@ -211,7 +211,19 @@ impl OpenTelemetryProtocolHandler for Instance {
|
||||
)
|
||||
})?;
|
||||
limiter.check_request_fits(bytes, held_bytes)?;
|
||||
let reservation = Arc::new(limiter.acquire(bytes).await?);
|
||||
// Holding body permits while waiting for expansion can stall concurrent requests.
|
||||
let reservation = Arc::new(if held_bytes > 0 {
|
||||
limiter.try_acquire(bytes).ok_or_else(|| {
|
||||
error::MemoryLimitExceededSnafu.into_error(
|
||||
common_memory_manager::Error::MemoryLimitExceeded {
|
||||
requested_bytes: bytes,
|
||||
limit_bytes: limiter.limit_bytes(),
|
||||
},
|
||||
)
|
||||
})?
|
||||
} else {
|
||||
limiter.acquire(bytes).await?
|
||||
});
|
||||
let mut ctx = ctx.fork();
|
||||
// Queued and detached writes retain the reservation after caller cancellation.
|
||||
ctx.set_write_progress(Arc::new(WriteProgress::with_reservation(reservation)));
|
||||
|
||||
@@ -1974,6 +1974,51 @@ WITH(
|
||||
.await
|
||||
.unwrap();
|
||||
let limit = 64 * 1024;
|
||||
let limiter = ServerMemoryLimiter::new(
|
||||
limit,
|
||||
OnExhaustedPolicy::Wait {
|
||||
timeout: Duration::from_secs(30),
|
||||
},
|
||||
);
|
||||
let body = limiter.acquire(limit / 2).await.unwrap();
|
||||
let concurrent_body = limiter.acquire(limit / 2).await.unwrap();
|
||||
// Body permits cannot be released while their requests wait for expansion.
|
||||
let error = tokio::time::timeout(
|
||||
Duration::from_secs(5),
|
||||
instance.metrics(
|
||||
request.clone(),
|
||||
ctx.clone(),
|
||||
Some((limiter.clone(), body.granted_bytes())),
|
||||
),
|
||||
)
|
||||
.await
|
||||
.expect("requests holding body permits must not wait for expansion")
|
||||
.unwrap_err();
|
||||
assert!(matches!(
|
||||
error,
|
||||
servers::error::Error::MemoryLimitExceeded {
|
||||
source: common_memory_manager::Error::MemoryLimitExceeded { .. },
|
||||
..
|
||||
}
|
||||
));
|
||||
assert_eq!(limiter.used_bytes(), limit);
|
||||
drop(concurrent_body);
|
||||
assert_eq!(
|
||||
instance
|
||||
.metrics(
|
||||
request.clone(),
|
||||
ctx.clone(),
|
||||
Some((limiter.clone(), body.granted_bytes())),
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
.accepted_data_points,
|
||||
1
|
||||
);
|
||||
assert_eq!(limiter.used_bytes(), body.granted_bytes());
|
||||
drop(body);
|
||||
assert_eq!(limiter.used_bytes(), 0);
|
||||
|
||||
let limiter = ServerMemoryLimiter::new(
|
||||
limit,
|
||||
OnExhaustedPolicy::Wait {
|
||||
|
||||
Reference in New Issue
Block a user