Skip to content

Commit 7fd47b9

Browse files
authored
feat(base): allow exceeded memory limit if no workload (#17785)
* feat(base): refactor parent memory state * feat(base): allow exceeed memory limit if no workload * feat(base): allow exceeed memory limit if no workload * feat(base): allow exceeed memory limit if no workload * feat(base): allow exceeed memory limit if no workload * feat(base): allow exceeed memory limit if no workload * feat(base): allow exceeed memory limit if no workload * feat(base): allow exceeed memory limit if no workload * feat(base): allow exceeed memory limit if no workload * feat(base): allow exceeed memory limit if no workload * feat(base): allow exceeed memory limit if no workload * feat(base): allow exceeed memory limit if no workload * feat(base): allow exceeed memory limit if no workload
1 parent 9d1bb03 commit 7fd47b9

24 files changed

+1240
-162
lines changed

src/binaries/query/entry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ async fn precheck_services(conf: &InnerConfig) -> Result<(), MainError> {
104104
if conf.query.max_memory_limit_enabled {
105105
let size = conf.query.max_server_memory_usage as i64;
106106
info!("Set memory limit: {}", size);
107-
GLOBAL_MEM_STAT.set_limit(size);
107+
GLOBAL_MEM_STAT.set_limit(size, false);
108108
}
109109

110110
#[cfg(not(target_os = "macos"))]

src/common/base/src/mem_allocator/tracker.rs

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -537,8 +537,10 @@ mod tests {
537537
use crate::runtime::GlobalStatBuffer;
538538
use crate::runtime::MemStat;
539539
use crate::runtime::MemStatBuffer;
540+
use crate::runtime::ParentMemStat;
540541
use crate::runtime::Thread;
541542
use crate::runtime::ThreadTracker;
543+
use crate::runtime::GLOBAL_QUERIES_MANAGER;
542544

543545
fn with_mock_env<
544546
T: Allocator + Send + Sync + 'static,
@@ -550,7 +552,11 @@ mod tests {
550552
global: Arc<MemStat>,
551553
) -> R {
552554
{
553-
let mem_stat = MemStat::create(GlobalUniqName::unique());
555+
let mem_stat = MemStat::create_child(
556+
GlobalUniqName::unique(),
557+
0,
558+
ParentMemStat::Normal(global.clone()),
559+
);
554560
let mut tracking_payload = ThreadTracker::new_tracking_payload();
555561
tracking_payload.mem_stat = Some(mem_stat.clone());
556562

@@ -582,7 +588,7 @@ mod tests {
582588
with_mock_env(
583589
test_function,
584590
DefaultAllocator::default(),
585-
Arc::new(MemStat::global()),
591+
Arc::new(MemStat::global(&GLOBAL_QUERIES_MANAGER)),
586592
);
587593
}
588594

@@ -610,7 +616,7 @@ mod tests {
610616
with_mock_env(
611617
test_function,
612618
DefaultAllocator::default(),
613-
Arc::new(MemStat::global()),
619+
Arc::new(MemStat::global(&GLOBAL_QUERIES_MANAGER)),
614620
);
615621
}
616622

@@ -641,7 +647,7 @@ mod tests {
641647
with_mock_env(
642648
test_function,
643649
DefaultAllocator::default(),
644-
Arc::new(MemStat::global()),
650+
Arc::new(MemStat::global(&GLOBAL_QUERIES_MANAGER)),
645651
);
646652
}
647653

@@ -666,7 +672,11 @@ mod tests {
666672
assert_eq!(GlobalStatBuffer::current().memory_usage, 0);
667673
};
668674

669-
with_mock_env(test_function, FailingAllocator, Arc::new(MemStat::global()));
675+
with_mock_env(
676+
test_function,
677+
FailingAllocator,
678+
Arc::new(MemStat::global(&GLOBAL_QUERIES_MANAGER)),
679+
);
670680
}
671681

672682
#[test]
@@ -695,7 +705,7 @@ mod tests {
695705
with_mock_env(
696706
test_function,
697707
DefaultAllocator::default(),
698-
Arc::new(MemStat::global()),
708+
Arc::new(MemStat::global(&GLOBAL_QUERIES_MANAGER)),
699709
);
700710
}
701711

@@ -721,7 +731,7 @@ mod tests {
721731
with_mock_env(
722732
test_function,
723733
DefaultAllocator::default(),
724-
Arc::new(MemStat::global()),
734+
Arc::new(MemStat::global(&GLOBAL_QUERIES_MANAGER)),
725735
);
726736
}
727737

@@ -760,7 +770,11 @@ mod tests {
760770
assert_eq!(GlobalStatBuffer::current().memory_usage, 0);
761771
};
762772

763-
with_mock_env(test_function, FailingAllocator, Arc::new(MemStat::global()));
773+
with_mock_env(
774+
test_function,
775+
FailingAllocator,
776+
Arc::new(MemStat::global(&GLOBAL_QUERIES_MANAGER)),
777+
);
764778
}
765779

766780
#[test]
@@ -836,7 +850,7 @@ mod tests {
836850
with_mock_env(
837851
test_function,
838852
PartialFailingAllocator(DefaultAllocator::default()),
839-
Arc::new(MemStat::global()),
853+
Arc::new(MemStat::global(&GLOBAL_QUERIES_MANAGER)),
840854
);
841855
}
842856

@@ -914,7 +928,7 @@ mod tests {
914928
with_mock_env(
915929
test_function,
916930
GrowZeroedFailingAllocator(DefaultAllocator::default()),
917-
Arc::new(MemStat::global()),
931+
Arc::new(MemStat::global(&GLOBAL_QUERIES_MANAGER)),
918932
);
919933
}
920934

@@ -991,7 +1005,7 @@ mod tests {
9911005
with_mock_env(
9921006
test_function,
9931007
ShrinkFailingAllocator(DefaultAllocator::default()),
994-
Arc::new(MemStat::global()),
1008+
Arc::new(MemStat::global(&GLOBAL_QUERIES_MANAGER)),
9951009
);
9961010
}
9971011

@@ -1204,7 +1218,7 @@ mod tests {
12041218
inner: DefaultAllocator::default(),
12051219
failure_rate: 0.3,
12061220
},
1207-
Arc::new(MemStat::global()),
1221+
Arc::new(MemStat::global(&GLOBAL_QUERIES_MANAGER)),
12081222
);
12091223
}
12101224

@@ -1241,13 +1255,13 @@ mod tests {
12411255
with_mock_env(
12421256
test_function,
12431257
DefaultAllocator::default(),
1244-
Arc::new(MemStat::global()),
1258+
Arc::new(MemStat::global(&GLOBAL_QUERIES_MANAGER)),
12451259
);
12461260
}
12471261

12481262
#[test]
12491263
fn test_dynamic_memstat_switch() {
1250-
let global = Arc::new(MemStat::global());
1264+
let global = Arc::new(MemStat::global(&GLOBAL_QUERIES_MANAGER));
12511265
let test_function = {
12521266
let global = global.clone();
12531267
move |mem_stat: Arc<MemStat>, _allocator: Arc<dyn Allocator + Send + Sync + 'static>| {
@@ -1311,7 +1325,7 @@ mod tests {
13111325

13121326
#[test]
13131327
fn test_thread_local_stat_isolation() {
1314-
let global_mem_stat = Arc::new(MemStat::global());
1328+
let global_mem_stat = Arc::new(MemStat::global(&GLOBAL_QUERIES_MANAGER));
13151329

13161330
let test_function = {
13171331
let global_mem_stat = global_mem_stat.clone();

0 commit comments

Comments
 (0)