Skip to content

Commit f434100

Browse files
authored
feat(query): enable memory percentage quota for the workload group (#18328)
1 parent eba0602 commit f434100

File tree

5 files changed

+405
-12
lines changed

5 files changed

+405
-12
lines changed

โ€Žsrc/common/base/src/runtime/memory/mem_stat.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ impl MemStat {
163163
}
164164
}
165165

166+
pub fn get_limit(&self) -> i64 {
167+
self.memory_limit.limit.load(Ordering::Relaxed)
168+
}
169+
166170
/// Feed memory usage stat to MemStat and return if it exceeds the limit.
167171
///
168172
/// It feeds `state` to the this tracker and all of its ancestors, including GLOBAL_TRACKER.

โ€Žsrc/common/base/src/runtime/workload_group.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use std::collections::HashMap;
1616
use std::fmt::Display;
1717
use std::fmt::Formatter;
18+
use std::sync::atomic::AtomicUsize;
1819
use std::sync::Arc;
1920
use std::time::Duration;
2021

@@ -62,14 +63,20 @@ pub struct WorkloadGroupResource {
6263
pub meta: WorkloadGroup,
6364
pub queue_key: String,
6465
pub mem_stat: Arc<MemStat>,
66+
pub max_memory_usage: Arc<AtomicUsize>,
6567
#[allow(clippy::type_complexity)]
66-
pub destroy_fn: Option<Box<dyn FnOnce(&str) + Send + Sync + 'static>>,
68+
pub destroy_fn: Option<Box<dyn FnOnce(&str, Option<usize>) + Send + Sync + 'static>>,
6769
}
6870

6971
impl Drop for WorkloadGroupResource {
7072
fn drop(&mut self) {
7173
if let Some(destroy_fn) = self.destroy_fn.take() {
72-
destroy_fn(&self.meta.id);
74+
let mut mem_percentage = None;
75+
if let Some(QuotaValue::Percentage(v)) = self.meta.quotas.get(MEMORY_QUOTA_KEY) {
76+
mem_percentage = Some(*v);
77+
}
78+
79+
destroy_fn(&self.meta.id, mem_percentage);
7380
}
7481
}
7582
}

โ€Žsrc/query/management/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#![feature(let_chains)]
16+
#![feature(get_mut_unchecked)]
1517
#![allow(clippy::uninlined_format_args)]
1618

1719
mod connection;

0 commit comments

Comments
ย (0)