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

Issue #5086 Review and rework o.e.j.util.Scanner #5744

Merged
merged 11 commits into from
Dec 2, 2020

Conversation

janbartel
Copy link
Contributor

Closes #5086

The issue task was review the locking strategy for the Scanner. I've done that, made changes to hopefully remove any necessity for locking, and also removed some methods that were deprecated in jetty-9.4. As part of the refactoring of the code, there were some behaviour changes in the reporting of file changes, which I don't believe will make any substantive difference ( I can't even remember why I put those specific behaviours in there in the first place) but I'll call them out here anyway:

  1. previously, we never reported a file as having been REMOVED until it had been missing for 2 scan cycles. I think that's unnecessary: when any scan detects a file has been deleted, a REMOVED event is issued for it.
  2. previously, if a file was added and then deleted in the next scan then subsequently popped back into existence it was reported as CHANGED. Now, if the file pops back into existence, it will reported as ADDED when it stabilizes, and REMOVED when it is deleted.

Note when reviewing: as a reminder of how the Scanner works, it is still the case that it takes at least 2 scan cycles to report a file as being ADDED: the first to detect the addition of the file, and the second to check that the file size or last modified time hasn't changed. Similarly, it takes at lesat 2 scan cycles to report a file as CHANGED: the first to detect the change, and the second to check the file size or last modified time hasn't changed.

@janbartel janbartel marked this pull request as ready for review December 1, 2020 17:28
@@ -135,7 +136,7 @@ public WebAppScannerListener(AntWebAppContext awc)
}

@Override
public void filesChanged(List<String> changedFileNames)
public void filesChanged(Set<String> changedFileNames)
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't like this. File names are unique by definition, so there is no risk of duplicates. I would not add additional randomness caused by Set. If I really don't care, I'd use Collection -- the Set is supposed to be immutable anyway, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure I understand your point. If it's a List then by definition I can have duplicates in a List, but I can't in a Set. Plus, you can't rely on ordering as it depends on the filesystem in what order scanned directories are visited, so List is a furphy.

@@ -140,7 +140,6 @@ protected void doStart() throws Exception
_scanner = new Scanner();
_scanner.setScanDirs(files);
_scanner.setScanInterval(_scanInterval);
_scanner.setRecursive(_recursive);
Copy link
Contributor

Choose a reason for hiding this comment

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

Scanner.setRecursive() was deprecated, but there is no Javadoc about why.
This is the only usage of ScanningAppProvider._recursive which then should also be deprecated and removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

public boolean equals(Object obj)
{
return ((Event)obj)._filename.equals(_filename) && ((Event)obj)._notification == _notification;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Add correspondent hashCode(). Use Objects.hash(...) if possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

assertTrue(_queue.isEmpty());

Copy link
Contributor

Choose a reason for hiding this comment

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

Spaces!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

private final List<Listener> _listeners = new ArrayList<>();
private final Map<String, TimeNSize> _prevScan = new HashMap<>();
private final Map<String, TimeNSize> _currentScan = new HashMap<>();
private AtomicInteger _scanCount = new AtomicInteger(0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Make it final.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

}

/**
* Scan all of the given paths.
*/
public void scanFiles()
public Map<String, MetaData> scanFiles()
Copy link
Contributor

Choose a reason for hiding this comment

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

Make it private because MetaData is package private.
Maybe make MetaData a private class too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -271,9 +270,13 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOEx
public void fileRemoved(String filename) throws Exception;
}

/**
* Notification of files that changed in the last scan.
*
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove extra newline.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

_scanInterval = scanInterval;
schedule();
}
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Spaces.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

}
schedule();
}

public TimerTask newTimerTask()
Copy link
Contributor

Choose a reason for hiding this comment

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

Make it private and replace with Jetty's Scheduler.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

*/
@Deprecated
public void setRecursive(boolean recursive)
public void setFilenameFilter(FilenameFilter filter)
Copy link
Contributor

Choose a reason for hiding this comment

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

Still worth to keep around Deprecated method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't really want to mess with the WebAppProvider's filter for finding webapps to deploy at this late stage - it can be refactored at a later stage, so I've raised #5748 to track it.

@janbartel
Copy link
Contributor Author

@sbordet I've done most if not all of things you requested so please rereview when ready. The failed build doesn't seem to have anything to do with this PR.

@janbartel
Copy link
Contributor Author

@sbordet I've done most if not all of things you requested so please rereview when ready. The failed build doesn't seem to have anything to do with this PR.

OOps, looks like it was actually a real problem, just heavily disguised in build paraphernalia. Should be fixed now.

janbartel and others added 3 commits December 2, 2020 09:03
More cleanups in code adding more privateness, getting rid of unnecessary exceptions, making fields final, etc.

Signed-off-by: Simone Bordet <[email protected]>
@sbordet
Copy link
Contributor

sbordet commented Dec 2, 2020

@janbartel I went on and polished this PR even more, you may want to review my commit.

@@ -135,8 +135,7 @@ public void scan()

_scanner.scan(callback);
_scanner.scan(callback);
complete.await(10, TimeUnit.SECONDS);

return complete.await(10, TimeUnit.SECONDS);
Copy link
Contributor

Choose a reason for hiding this comment

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

@sbordet this will return true even if the callback fails, which is a bit strange.

Copy link
Contributor

Choose a reason for hiding this comment

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

@gregw I don't understand? If the 10 s elapsed, complete.await() would have returned false, and the return value would have been ignored. Now we return it so that a JMX call to this method would know if it timed out.

Copy link
Contributor

Choose a reason for hiding this comment

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

Scan is passed a callback. If it is failed then this method should return false. Moreover I think if it times out then I think this method should throw a timeout exception rather than return

Copy link
Contributor

Choose a reason for hiding this comment

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

@sbordet ^

Also I don't like the 10second wait either, but not sure how to avoid other than infinite wait

@sbordet sbordet requested a review from gregw December 2, 2020 16:41
@sbordet sbordet merged commit 0eccdde into jetty-10.0.x Dec 2, 2020
@sbordet sbordet deleted the jetty-10.0.x-5086-review-scanner branch December 2, 2020 18:25
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.

Review Scanner locking
3 participants