Skip to content
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

FileTarget - Validate File CreationTimeUtc when non-Windows #1931

Merged
merged 1 commit into from Feb 5, 2017

Conversation

snakefoot
Copy link
Contributor

@snakefoot snakefoot commented Jan 24, 2017

Simple fallback to FileLastWriteTimeUtc, when FileCreationTimeUtc is very old (when non-windows). Simple fix for #1633

Also fixes bug in UnixMultiProcessFileAppender, where the fileExists-check was wrongly done after having created the file-descriptor.

This change is Reviewable

@codecov-io
Copy link

codecov-io commented Jan 24, 2017

Codecov Report

❗ No coverage uploaded for pull request base (master@fc487be). Click here to learn what that means.

@@           Coverage Diff            @@
##             master   #1931   +/-   ##
========================================
  Coverage          ?     81%           
========================================
  Files             ?     285           
  Lines             ?   19554           
  Branches          ?    2288           
========================================
  Hits              ?   15924           
  Misses            ?    3081           
  Partials          ?     549

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fc487be...a753bba. Read the comment docs.

@snakefoot snakefoot force-pushed the FileTargetFileCreationTime branch 2 times, most recently from c2b8b50 to 285d643 Compare January 24, 2017 20:23
@@ -439,7 +452,16 @@ public Mutex GetArchiveMutex(string fileName)
var fileInfo = new FileInfo(filePath);
if (fileInfo.Exists)
{
return Time.TimeSource.Current.FromSystemTime(fileInfo.GetCreationTimeUtc());
result = fileInfo.GetCreationTimeUtc();
if (result.Value.Year < 1980)
Copy link
Member

Choose a reason for hiding this comment

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

could we get rid of the code duplication?

Maybe something like useFallBack(dateTime r) => r.Year < 1980 && !PlatformDetector.IsDesktopWin32 ?

Copy link
Member

Choose a reason for hiding this comment

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

or at least move the 1980 to a (internal) const.

Copy link
Member

@304NotModified 304NotModified left a comment

Choose a reason for hiding this comment

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

some code duplication notes

@snakefoot snakefoot force-pushed the FileTargetFileCreationTime branch 5 times, most recently from a284bd2 to 0abcb1e Compare January 28, 2017 10:19
@snakefoot
Copy link
Contributor Author

some code duplication notes

@304NotModified Have now created a helper-method, that handles the fallback logic.

@304NotModified 304NotModified modified the milestone: 4.4.2 Feb 3, 2017
#else
this.CreationTimeUtc = File.GetCreationTime(this.FileName);
#endif
this.CreationTimeUtc = FileCharacteristicsHelper.ValidateFileCreationTime(fileInfo, (f) => f.GetCreationTimeUtc(), (f) => f.GetLastWriteTimeUtc()).Value;
Copy link
Member

Choose a reason for hiding this comment

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

not trying to be nitpicking, but isn't this infecting the performance? AFAIK lamba's have there costs, and this code is called a lot?

Copy link
Contributor Author

@snakefoot snakefoot Feb 3, 2017

Choose a reason for hiding this comment

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

This code is called when opening the file. So it is only when using the RetryingMultiProcessAppender it is called a lot. But one can usually only allocate 500 FileStream-objects per second.

Also the lambdas are completely static without capture of this, so the compiler should turn them into zero allocations.

Ran a performance profiler of memory allocations using the RetryingMultiProcessAppender, and it within the BaseFileAppender.UpdateCreationTime() then the most expensive was the FileInfo-allocation, and the second most expensive was assigning the CreationTimeUtc where it used DateTime.ToLocalTime().

Copy link
Member

Choose a reason for hiding this comment

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

👍

@304NotModified 304NotModified added file-target bug Bug report / Bug fix enhancement Improvement on existing feature labels Feb 5, 2017
@304NotModified
Copy link
Member

partly fixes #1633, as this is merged to master and not (yet) to CoreCLR branch

@304NotModified 304NotModified merged commit 6fdf94f into NLog:master Feb 5, 2017
@snakefoot snakefoot mentioned this pull request Feb 27, 2017
@snakefoot snakefoot deleted the FileTargetFileCreationTime branch October 10, 2017 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug report / Bug fix enhancement Improvement on existing feature file-target
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants