mirror of
https://github.com/openai/codex.git
synced 2026-11-18 15:01:48 +00:00
feat: log db better maintenance (#16330)
Run a DB clean-up more frequently with an incremental `VACCUM` in it
This commit is contained in:
1 parent
f396454097
commit
868ac158d7
4 files changed
+125
-20
No files matched your search
@@ -18,8 +18,6 @@
|
||||
//! # }
|
||||
//! ```
|
||||
|
||||
use chrono::Duration as ChronoDuration;
|
||||
use chrono::Utc;
|
||||
use std::sync::OnceLock;
|
||||
use std::time::Duration;
|
||||
use std::time::SystemTime;
|
||||
@@ -47,8 +45,6 @@ use crate::StateRuntime;
|
||||
const LOG_QUEUE_CAPACITY: usize = 512;
|
||||
const LOG_BATCH_SIZE: usize = 128;
|
||||
const LOG_FLUSH_INTERVAL: Duration = Duration::from_secs(2);
|
||||
const LOG_RETENTION_DAYS: i64 = 10;
|
||||
|
||||
pub struct LogDbLayer {
|
||||
sender: mpsc::Sender<LogDbCommand>,
|
||||
process_uuid: String,
|
||||
@@ -58,7 +54,6 @@ pub fn start(state_db: std::sync::Arc<StateRuntime>) -> LogDbLayer {
|
||||
let process_uuid = current_process_log_uuid().to_string();
|
||||
let (sender, receiver) = mpsc::channel(LOG_QUEUE_CAPACITY);
|
||||
tokio::spawn(run_inserter(std::sync::Arc::clone(&state_db), receiver));
|
||||
tokio::spawn(run_retention_cleanup(state_db));
|
||||
|
||||
LogDbLayer {
|
||||
sender,
|
||||
@@ -337,14 +332,6 @@ async fn flush(state_db: &std::sync::Arc<StateRuntime>, buffer: &mut Vec<LogEntr
|
||||
let _ = state_db.insert_logs(entries.as_slice()).await;
|
||||
}
|
||||
|
||||
async fn run_retention_cleanup(state_db: std::sync::Arc<StateRuntime>) {
|
||||
let Some(cutoff) = Utc::now().checked_sub_signed(ChronoDuration::days(LOG_RETENTION_DAYS))
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let _ = state_db.delete_logs_before(cutoff.timestamp()).await;
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct MessageVisitor {
|
||||
message: Option<String>,
|
||||
|
||||
Reference in new issue
Block a user