Enhance Error Handling and Cleanup in `rotateLog` for Robust WAL Rotation
Author: ayushsatyam146Created May 30, 2025Updated May 30, 2025
Currently, rotateLog method returns errors for sync and csf.Close, but explicitly panics if opening a new segment file fails. This panic behavior is not good for a robust WAL system, as it can lead to application crashes and potential data inconsistency or corruption if a new segment cannot be created.
- Figure out the critical edge cases and conditions where this method will throw error and handle them gracefully or return properly logged error messages.
- Replace the panic during os.OpenFile failure with a graceful error return, logging the critical failure.
- Review
periodicRotateSegment: Ensure the caller of rotateLog (periodicRotateSegment) is equipped to handle the returned errors gracefully (e.g., logging, retries, or shutting down if unrecoverable).
Refer the below TODOs in the method for more context
// TODO: Ideally this function should not return any error
// Check for the conditions where it can return an error
// and handle them gracefully.
// I fear that we will need to do some cleanup operations in case of errors.// TODO: We are panicking here because we are not handling the error
// and we want to make sure that the WAL is not corrupted.
// We need to handle this error gracefully.Setup Instructions
- setup DiceDB server locally from the source - instructions
- setup DiceDB Go SDK locally from the source - instructions
- setup DiceDB CLI locally from the source - instructions
- refer to the
Pointing to local checked-outdicedb-gosection inREADME`.
Start the DiceDB server
$ go run main.go --log-level debugFollow the contribution guidelines
These are general guidelines to follow before you submit a patch. Please mark them as done once you complete them
- please go through the CONTRIBUTING guide
- follow LOGGING best practices
- follow Golang best practices
- run
make linton your local copy of the codebase
Source: dicedb/dicedb