Skip to content

Commit d12c16b

Browse files
committed
fix(server): optimize log rotation and fix active log file deletion issues
- Rename variables (max_size => max_file_size, internal attributions) - Configure customize rotation check option and redirect default unwrap values - Fix prevention of active log file deletion - Optimize thread handling (graceful shutdown, thread communication) - Validate invalid configuration parameters - Sync e2e/server.toml configuration - Use full semantic versioning for dependencies
1 parent 4e3a7cd commit d12c16b

File tree

8 files changed

+246
-85
lines changed

8 files changed

+246
-85
lines changed

core/configs/server.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,12 +363,17 @@ level = "info"
363363
# When enabled, logs are stored in {system.path}/{system.logging.path} (default: local_data/logs).
364364
file_enabled = true
365365

366-
# Maximum size of the log files before rotation.
367-
max_size = "512 MB"
366+
# Maximum size of a single log file before rotation occurs.
367+
# When a log file reaches this size, it will be rotated (closed and a new file created).
368+
# This setting works together with max_total_size to control log storage.
369+
max_file_size = "512 MB"
368370

369371
# Maximum total size of all log files combined.
370372
# When this size is reached, oldest files will be deleted.
371-
max_total_size = "10 GB"
373+
max_total_size = "4 GB"
374+
375+
# Time interval for checking log file size and rotation.
376+
rotation_check_interval = "1 h"
372377

373378
# Time to retain log files before deletion.
374379
retention = "7 days"

core/server/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ error_set = { workspace = true }
6767
figlet-rs = { workspace = true }
6868
figment = { workspace = true }
6969
flume = { workspace = true }
70-
fs2 = "0.4"
70+
fs2 = "0.4.3"
7171
futures = { workspace = true }
7272
hash32 = "1.0.0"
7373
human-repr = { workspace = true }

core/server/src/configs/defaults.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,14 @@ impl Default for LoggingConfig {
402402
path: SERVER_CONFIG.system.logging.path.parse().unwrap(),
403403
level: SERVER_CONFIG.system.logging.level.parse().unwrap(),
404404
file_enabled: SERVER_CONFIG.system.logging.file_enabled,
405-
max_size: SERVER_CONFIG.system.logging.max_size.parse().unwrap(),
405+
max_file_size: SERVER_CONFIG.system.logging.max_file_size.parse().unwrap(),
406406
max_total_size: SERVER_CONFIG.system.logging.max_total_size.parse().unwrap(),
407+
rotation_check_interval: SERVER_CONFIG
408+
.system
409+
.logging
410+
.rotation_check_interval
411+
.parse()
412+
.unwrap(),
407413
retention: SERVER_CONFIG.system.logging.retention.parse().unwrap(),
408414
sysinfo_print_interval: SERVER_CONFIG
409415
.system

core/server/src/configs/displays.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl Display for ServerConfig {
170170
}
171171

172172
impl Display for MessageSaverConfig {
173-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
173+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
174174
write!(
175175
f,
176176
"{{ enabled: {}, enforce_fsync: {}, interval: {} }}",
@@ -253,7 +253,7 @@ impl Display for LoggingConfig {
253253
self.path,
254254
self.level,
255255
self.file_enabled,
256-
self.max_size.as_human_string_with_zero_as_unlimited(),
256+
self.max_file_size.as_human_string_with_zero_as_unlimited(),
257257
self.retention
258258
)
259259
}

core/server/src/configs/system.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@
1616
* under the License.
1717
*/
1818

19+
use super::cache_indexes::CacheIndexesConfig;
20+
use super::sharding::ShardingConfig;
1921
use crate::configs::server::MemoryPoolConfig;
2022
use crate::slab::partitions;
2123
use crate::slab::streams;
2224
use crate::slab::topics;
23-
24-
use super::cache_indexes::CacheIndexesConfig;
25-
use super::sharding::ShardingConfig;
2625
use iggy_common::IggyByteSize;
2726
use iggy_common::IggyError;
2827
use iggy_common::IggyExpiry;
@@ -87,20 +86,16 @@ pub struct LoggingConfig {
8786
pub path: String,
8887
pub level: String,
8988
pub file_enabled: bool,
90-
pub max_size: IggyByteSize,
91-
#[serde(default = "default_max_total_log_size")]
89+
pub max_file_size: IggyByteSize,
9290
pub max_total_size: IggyByteSize,
9391
#[serde_as(as = "DisplayFromStr")]
92+
pub rotation_check_interval: IggyDuration,
93+
#[serde_as(as = "DisplayFromStr")]
9494
pub retention: IggyDuration,
9595
#[serde_as(as = "DisplayFromStr")]
9696
pub sysinfo_print_interval: IggyDuration,
9797
}
9898

99-
fn default_max_total_log_size() -> IggyByteSize {
100-
IggyByteSize::from(10 * 1024 * 1024 * 1024)
101-
// 10 GiB by default
102-
}
103-
10499
#[derive(Debug, Deserialize, Serialize)]
105100
pub struct EncryptionConfig {
106101
pub enabled: bool,

core/server/src/configs/validators.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use super::server::{
2222
DataMaintenanceConfig, MessageSaverConfig, MessagesMaintenanceConfig, TelemetryConfig,
2323
};
2424
use super::sharding::{CpuAllocation, ShardingConfig};
25-
use super::system::{CompressionConfig, PartitionConfig};
25+
use super::system::{CompressionConfig, LoggingConfig, PartitionConfig};
2626
use crate::configs::COMPONENT;
2727
use crate::configs::server::{MemoryPoolConfig, PersonalAccessTokenConfig, ServerConfig};
2828
use crate::configs::sharding::NumaTopology;
@@ -85,6 +85,13 @@ impl Validatable<ConfigurationError> for ServerConfig {
8585
format!("{COMPONENT} (error: {e}) - failed to validate cluster config")
8686
})?;
8787

88+
self.system
89+
.logging
90+
.validate()
91+
.error(|e: &iggy_common::ConfigurationError| {
92+
format!("{COMPONENT} (error: {e}) - failed to validate logging config")
93+
})?;
94+
8895
let topic_size = match self.system.topic.max_size {
8996
MaxTopicSize::Custom(size) => Ok(size.as_bytes_u64()),
9097
MaxTopicSize::Unlimited => Ok(u64::MAX),
@@ -255,6 +262,32 @@ impl Validatable<ConfigurationError> for PersonalAccessTokenConfig {
255262
}
256263
}
257264

265+
impl Validatable<ConfigurationError> for LoggingConfig {
266+
fn validate(&self) -> Result<(), ConfigurationError> {
267+
if self.level.is_empty() {
268+
return Err(ConfigurationError::InvalidConfigurationValue);
269+
}
270+
271+
if self.retention.as_secs() < 1 {
272+
error!(
273+
"Configured system.logging.retention {} is less than minimum 1 second",
274+
self.retention
275+
);
276+
return Err(ConfigurationError::InvalidConfigurationValue);
277+
}
278+
279+
if self.max_total_size.as_bytes_u64() < self.max_file_size.as_bytes_u64() {
280+
error!(
281+
"Configured system.logging.max_total_size {} is less than system.logging.max_file_size {}",
282+
self.max_total_size, self.max_file_size
283+
);
284+
return Err(ConfigurationError::InvalidConfigurationValue);
285+
}
286+
287+
Ok(())
288+
}
289+
}
290+
258291
impl Validatable<ConfigurationError> for MemoryPoolConfig {
259292
fn validate(&self) -> Result<(), ConfigurationError> {
260293
if self.enabled && self.size == 0 {

0 commit comments

Comments
 (0)