@@ -24,8 +24,8 @@ use crate::journalentry::JournalEntry;
2424use crate :: journalrw:: { GetLog2Params , GetLog2Since , JournalReaderLog2 , JournalWriterLog2 , Log2Reader } ;
2525use crate :: sites:: { SitesData , SubHpInfo } ;
2626use crate :: tree:: { FileType , LsFilesEntry , METH_READ } ;
27- use crate :: util:: { get_files, is_log2_file, DedupReceiver } ;
28- use crate :: { State , MAX_JOURNAL_DIR_SIZE_DEFAULT } ;
27+ use crate :: util:: { get_files, is_log2_file, msec_to_log2_filename , DedupReceiver } ;
28+ use crate :: { HpConfig , State } ;
2929
3030#[ derive( Default ) ]
3131pub ( crate ) struct SyncInfo {
@@ -542,13 +542,6 @@ async fn sync_site_legacy(
542542 const GETLOG_SINCE_DAYS_DEFAULT : i64 = 365 ;
543543 const RECORD_COUNT_LIMIT : i64 = 10000 ;
544544
545- fn msec_to_log2_filename ( msec : i64 ) -> String {
546- shvproto:: DateTime :: from_epoch_msec ( msec)
547- . to_chrono_datetime ( )
548- . format ( "%Y-%m-%dT%H-%M-%S-%3f.log2" )
549- . to_string ( )
550- }
551-
552545 let ( mut getlog_params, mut log_file_path, mut log_file_entries) = match newest_log {
553546 Some ( ( newest_log_file, newest_log_entries) ) => {
554547 let last_log_entry_msec = newest_log_entries. last ( ) . expect ( "The newest log is not empty" ) . epoch_msec ;
@@ -699,6 +692,11 @@ async fn sync_site_legacy(
699692
700693const MAX_SYNC_TASKS_DEFAULT : usize = 8 ;
701694
695+ pub fn log_size_limit ( config : & HpConfig ) -> u64 {
696+ const MAX_JOURNAL_DIR_SIZE_DEFAULT : usize = 30 * 1_000_000_000 ;
697+ config. max_journal_dir_size . unwrap_or ( MAX_JOURNAL_DIR_SIZE_DEFAULT ) as u64
698+ }
699+
702700pub ( crate ) async fn sync_task (
703701 client_cmd_tx : ClientCommandSender ,
704702 _client_evt_rx : ClientEventsReceiver ,
@@ -723,7 +721,8 @@ pub(crate) async fn sync_task(
723721
724722 // The download size limit should be lower than the max_journal_dir_size, because it doesn't
725723 // count in the files synced by getLog.
726- let max_journal_dir_size = app_state. config . max_journal_dir_size . unwrap_or ( MAX_JOURNAL_DIR_SIZE_DEFAULT ) as u64 ;
724+ let max_journal_dir_size = log_size_limit ( & app_state. config ) ;
725+ let days_to_keep = app_state. config . days_to_keep . unwrap_or ( 0 ) ;
727726
728727 while let Some ( cmd) = sync_cmd_rx. next ( ) . await {
729728 match cmd {
@@ -819,7 +818,7 @@ pub(crate) async fn sync_task(
819818 panic ! ( "Cannot send dirtylog Trim command for site {site}: {e}" )
820819 )
821820 ) ;
822- match cleanup_log2_files ( & app_state. config . journal_dir , max_journal_dir_size) . await {
821+ match cleanup_log2_files ( & app_state. config . journal_dir , max_journal_dir_size, days_to_keep ) . await {
823822 Ok ( _) => info ! ( "Cleanup journal dir done" ) ,
824823 Err ( err) => error ! ( "Cleanup journal dir error: {err}" ) ,
825824 }
@@ -883,7 +882,7 @@ pub(crate) async fn sync_task(
883882 . unwrap_or_else ( |e|
884883 panic ! ( "Cannot send dirtylog Trim command for site {site}: {e}" )
885884 ) ;
886- match cleanup_log2_files ( & app_state. config . journal_dir , max_journal_dir_size) . await {
885+ match cleanup_log2_files ( & app_state. config . journal_dir , max_journal_dir_size, days_to_keep ) . await {
887886 Ok ( _) => info ! ( "Cleanup journal dir done" ) ,
888887 Err ( err) => error ! ( "Cleanup journal dir error: {err}" ) ,
889888 }
@@ -893,7 +892,7 @@ pub(crate) async fn sync_task(
893892 }
894893 SyncCommand :: Cleanup => {
895894 info ! ( "Cleanup journal dir start" ) ;
896- match cleanup_log2_files ( & app_state. config . journal_dir , max_journal_dir_size) . await {
895+ match cleanup_log2_files ( & app_state. config . journal_dir , max_journal_dir_size, days_to_keep ) . await {
897896 Ok ( _) => info ! ( "Cleanup journal dir done" ) ,
898897 Err ( err) => error ! ( "Cleanup journal dir error: {err}" ) ,
899898 }
0 commit comments