-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Round initialTime
in RollingFileManager
#3872
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
While @ppkarwasz is the main figure stewarding #3068 and this one, I'd appreciate one or more new tests and a changelog entry. |
@vy If you have an idea on how to test this properly, I'm happy to write a test. |
@kelunik, create a package-private |
@vy I've added a test now in a similar way like you suggested. It tests the rounding now, but doesn't test the fact that initial time actually rounds. I've also modified the test in the second commit to actually call |
log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java
Outdated
Show resolved
Hide resolved
Caching of filesystem timestamps (at least in ext4 on Linux) results in non-accurate creation timestamp. Thus, let's round it to the second. Rounding is also applied for the lastModified time, but I'm not sure whether it's needed there. Fixes apache#3068.
Rounding the creation date from the filesystem might address the immediate issue, but I was wondering if it might be more robust to initialize the policy using the file’s last modification date instead:
Would you see any downsides to this alternative? |
Yes, see #3068 (comment)
Additionally, relying on the creation date isn't a known issue, so no action needed here IMO. |
@ppkarwasz Seems like the same caching also applies to the modification time, as I suspected, see https://stackoverflow.com/q/14392975/2373138. |
To counteract this problem the My point here is that no Java API allows us to change the creation date, but with the last modification date we have full control. |
I know, but we don't need that full control if rounding to the full second is acceptable for the initial time. I'd prefer to see the bug finally fixed, unless you see a major downside with this approach. Relying on the birth time seems much more appropriate than back-dating the last modification time. Back-dating the modification time can still be implemented later if someone on a system not supporting birth time has a need for that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[@ppkarwasz writes] My point here is that no Java API allows us to change the creation date, but with the last modification date we have full control.
[@kelunik writes] I know, but we don't need that full control if rounding to the full second is acceptable for the initial time. I'd prefer to see the bug finally fixed, unless you see a major downside with this approach.
Relying on the birth time seems much more appropriate than back-dating the last modification time.
I agree with @kelunik here for following reasons:
- He has already explained using the last modification time has problems
- Resetting the last modification time to creation time – i.e., altering the truth – to make it work with Log4j does not sound right to me.
- Using creation time without its sub-second components already fixes the issue
@ppkarwasz, I'm inclined to accept this patch. Do you have objections?
Go ahead! I still think we should not rely on the creation time at all (the JDK falls back on the last modification time in many versions and filesystems; we experienced this directly when the |
initialTime
in RollingFileManager
Caching of filesystem timestamps (at least in ext4 on Linux) results in non-accurate creation timestamps.
Thus, let's round it to the second.
Rounding is also applied for the lastModified time, but I'm not sure whether it's needed there.
Fixes #3068.
✅ Required checks
🧪 Tests (select one)
📝 Changelog (select one)
src/changelog/.2.x.x
. (See Changelog Entry File Guide).