Skip to content

Commit afe5380

Browse files
committed
feat: add mem exceeded exception
1 parent 3663b93 commit afe5380

4 files changed

Lines changed: 20 additions & 1 deletion

File tree

agent/src/exception.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ impl ExceptionHandler {
4949
}
5050
}
5151

52+
pub fn peek(&self) -> u64 {
53+
self.exception.load(Ordering::Relaxed)
54+
}
55+
5256
pub fn has(&self, e: Exception) -> bool {
5357
let e = e as u64;
5458
self.exception.load(Ordering::Relaxed) & e == e

agent/src/rpc/synchronizer.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2064,7 +2064,14 @@ impl Synchronizer {
20642064
info!("sync interval set to {:?}", sync_interval);
20652065
}
20662066

2067-
time::sleep(sync_interval).await;
2067+
let last_exception = exception_handler.peek();
2068+
let count = sync_interval.as_secs().max(1);
2069+
for _ in 0..count {
2070+
time::sleep(Duration::from_secs(1)).await;
2071+
if last_exception != exception_handler.peek() {
2072+
break;
2073+
}
2074+
}
20682075
}
20692076
}));
20702077
}

agent/src/utils/guard.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,7 @@ impl Guard {
698698
match get_memory_rss() {
699699
Ok(memory_usage) => {
700700
if memory_usage >= memory_limit {
701+
exception_handler.set(Exception::MemExceeded, None);
701702
if over_memory_limit {
702703
error!(
703704
"memory usage over memory limit twice, current={}, memory_limit={}, deepflow-agent restart...",
@@ -712,12 +713,18 @@ impl Guard {
712713
);
713714
over_memory_limit = true;
714715
}
716+
} else {
717+
over_memory_limit = false;
718+
exception_handler.clear(Exception::MemExceeded);
715719
}
716720
}
717721
Err(e) => {
718722
warn!("{}", e);
719723
}
720724
}
725+
} else {
726+
over_memory_limit = false;
727+
exception_handler.clear(Exception::MemExceeded);
721728
}
722729
}
723730

message/agent.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ enum Exception {
7878
DATA_BPS_THRESHOLD_EXCEEDED = 2097152;
7979
FREE_DISK_CIRCUIT_BREAKER = 4194304;
8080
KERNEL_VERSION_CIRCUIT_BREAKER = 8388608;
81+
MEM_EXCEEDED = 16777216;
8182
// 2^31及以下由 agent ,agent 最大可用异常是2^31,顺序从前往后
8283
// 2^32及以上由控制器使用,顺序从后往前
8384
}

0 commit comments

Comments
 (0)