Skip to content

Conversation

@Svecco
Copy link

@Svecco Svecco commented Dec 7, 2025

Redirected from issue #46 , the progress:

  • Implemented _install_log_rotation_handler function, which was previously marked as todo;
  • Implemented cleanup_log_files to delete logs based on the configured time threshold & size;
  • Merged multiple directory traversals into a single traversal;
  • Reduced multiple metadata() calls by collecting data in single traversal;
  • Split log cleanup logic into smaller, more manageable functions;
  • Improved error handling with detailed error messages and proper error propagation;
  • Fixed an issue where the directory did not exist when loading logs;
  • Added disk space checking before initializing file logging;

Before merge:

  • Verified to comply with Apache specifications;
  • Add a relevant unit test for logging;
  • Confirm that the code has been optimized well?
  • Squash commits to a proper number after polishing;
  • Solve conflicts and confirm it is ready for being merged;

Plan:
Around the next several weekends.

@hubcio
Copy link
Contributor

hubcio commented Dec 7, 2025

I think changes in core/message_bus are not related to log retention, looks like merge problem.

Svecco added a commit to Svecco/iggy that referenced this pull request Dec 13, 2025
…retention

- Configurable maximum log size and retention period from server configuration
- Optimized single directory traversal for collecting file information
- Eliminated redundant metadata() calls for improved performance
- Enhanced error handling with detailed logging for all failure cases
- Merged directory traversals into a single operation to improve performance

Fixes apache#46, detail changes can be found at apache#2452.
@Svecco Svecco marked this pull request as ready for review December 13, 2025 03:04
@Svecco
Copy link
Author

Svecco commented Dec 13, 2025

I think changes in core/message_bus are not related to log retention, looks like merge problem.

Yes, that was the case. I have just rebased it to the correct state.

Svecco added a commit to Svecco/iggy that referenced this pull request Dec 20, 2025
…retention

- Configurable maximum log size and retention period from server configuration
- Optimized single directory traversal for collecting file information
- Eliminated redundant metadata() calls for improved performance
- Enhanced error handling with detailed logging for all failure cases
- Merged directory traversals into a single operation to improve performance

Fixes apache#46, detail changes can be found at apache#2452.
@Svecco Svecco requested review from hubcio and spetz December 20, 2025 12:28
@Svecco Svecco force-pushed the 46-size-logs branch 2 times, most recently from 8a52d32 to a1c8c0f Compare December 27, 2025 12:23
@Svecco
Copy link
Author

Svecco commented Dec 27, 2025

@hubcio @spetz I've just squashed commits into one.

Svecco added 2 commits January 1, 2026 17:18
…retention

- Configurable maximum log size and retention period from server configuration
- Optimized single directory traversal for collecting file information
- Eliminated redundant metadata() calls for improved performance
- Enhanced error handling with detailed logging for all failure cases
- Merged directory traversals into a single operation to improve performance

Fixes apache#46, detail changes can be found at apache#2452.
- Log directory creation functionality
- Disk space checking feature
- Log file count calculation
- Log cleanup functions
- Logging struct initialization
- Fixed some problems
@Svecco
Copy link
Author

Svecco commented Jan 1, 2026

I deliberately set some values to conduct a simple test of the current log rotation functionality. Generally speaking, it should now be operating normally.

Console
2026-01-01T09:03:36.553786Z  INFO shard-12 server::websocket::websocket_listener: WebSocket config: max_message_size: None, max_frame_size: None, accept_unmasked_frames: false
2026-01-01T09:03:37.523106Z DEBUG log-rotation server::log::logger: Starting log cleanup for directory: "local_data/logs", retention: 3600s, max_total_size: 4000000000 bytes, max_single_file_size: 512000000 bytes
2026-01-01T09:03:37.523237Z DEBUG log-rotation server::log::logger: Processed 4 log files from directory: "local_data/logs"
2026-01-01T09:03:37.523250Z DEBUG log-rotation server::log::logger: Mark old log file for remove: "local_data/logs/iggy-server.log.4"
2026-01-01T09:03:37.523260Z DEBUG log-rotation server::log::logger: Mark old log file for remove: "local_data/logs/iggy-server.log.1"
2026-01-01T09:03:37.523265Z DEBUG log-rotation server::log::logger: Mark old log file for remove: "local_data/logs/iggy-server.log.3"
2026-01-01T09:03:37.523270Z DEBUG log-rotation server::log::logger: Mark old log file for remove: "local_data/logs/iggy-server.log.2"
2026-01-01T09:03:37.530455Z DEBUG log-rotation server::log::logger: Removed log file: "local_data/logs/iggy-server.log.2"
2026-01-01T09:03:37.562069Z DEBUG log-rotation server::log::logger: Removed log file: "local_data/logs/iggy-server.log.3"
2026-01-01T09:03:37.569756Z DEBUG log-rotation server::log::logger: Removed log file: "local_data/logs/iggy-server.log.1"
2026-01-01T09:03:37.657651Z DEBUG log-rotation server::log::logger: Removed log file: "local_data/logs/iggy-server.log.4"
2026-01-01T09:03:37.657759Z  INFO log-rotation server::log::logger: Completed log cleanup for directory: "local_data/logs". Removed 4 files.
2026-01-01T09:03:38.657860Z DEBUG log-rotation server::log::logger: Starting log cleanup for directory: "local_data/logs", retention: 3600s, max_total_size: 4000000000 bytes, max_single_file_size: 512000000 bytes
2026-01-01T09:03:38.657958Z DEBUG log-rotation server::log::logger: Processed 0 log files from directory: "local_data/logs"
2026-01-01T09:03:38.657972Z  INFO log-rotation server::log::logger: Completed log cleanup for directory: "local_data/logs". Removed 0 files.
2026-01-01T09:03:39.658081Z DEBUG log-rotation server::log::logger: Starting log cleanup for directory: "local_data/logs", retention: 3600s, max_total_size: 4000000000 bytes, max_single_file_size: 512000000 bytes
2026-01-01T09:03:39.658171Z DEBUG log-rotation server::log::logger: Processed 0 log files from directory: "local_data/logs"
2026-01-01T09:03:39.658184Z  INFO log-rotation server::log::logger: Completed log cleanup for directory: "local_data/logs". Removed 0 files.
2026-01-01T09:03:40.658282Z DEBUG log-rotation server::log::logger: Starting log cleanup for directory: "local_data/logs", retention: 3600s, max_total_size: 4000000000 bytes, max_single_file_size: 512000000 bytes
2026-01-01T09:03:40.658376Z DEBUG log-rotation server::log::logger: Processed 0 log files from directory: "local_data/logs"
2026-01-01T09:03:40.658389Z  INFO log-rotation server::log::logger: Completed log cleanup for directory: "local_data/logs". Removed 0 files.

…ssues

- 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
Copy link
Contributor

@hubcio hubcio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested your code manually. In server.toml i changed settings to:

max_file_size = "1 MB"
max_total_size = "10 MB"
rotation_check_interval = "1 s"

then I rebulilt server and started it via:
RUST_LOG=trace target/debug/iggy-server --with-default-root-credentials --fresh

and in other shell i run benchmark to generate logs:
target/debug/iggy-bench -T 1000MB pp -p 1 tcp

result:
I can never see more than 2 files, it looks like retention is ignored and 10 MB of max total size is not reached.

can you write integration test that would test for this scenario? see how TestServer is used, in integration module (e.g. core/integration/tests/server/specific.rs)

}
}

info!(
Copy link
Contributor

@hubcio hubcio Jan 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont print anything if 0 files were removed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants