Fix not to perform clean up during scan

(#1550)
master
tesshucom 5 years ago committed by François-Xavier Thomas
parent 74b281a078
commit e635055bf6
  1. 40
      airsonic-main/src/main/java/org/airsonic/player/controller/MusicFolderSettingsController.java
  2. 2
      airsonic-main/src/main/java/org/airsonic/player/service/search/IndexManager.java

@ -101,29 +101,41 @@ public class MusicFolderSettingsController {
}
private void expunge() {
private synchronized void expunge() {
// to be before dao#expunge
MediaLibraryStatistics statistics = indexManager.getStatistics();
if (statistics != null) {
/*
* indexManager#expunge depends on DB delete flag.
* For consistency, clean of DB and Lucene must run in one block.
*
* Lucene's writing is exclusive.
* This process cannot be performed
* while during scan or scan has never been performed.
*/
if (statistics != null && !mediaScannerService.isScanning()) {
// to be before dao#expunge
LOG.debug("Cleaning search index...");
indexManager.startIndexing();
indexManager.expunge();
indexManager.stopIndexing(statistics);
LOG.debug("Search index cleanup complete.");
// to be after indexManager#expunge
LOG.debug("Cleaning database...");
LOG.debug("Deleting non-present artists...");
artistDao.expunge();
LOG.debug("Deleting non-present albums...");
albumDao.expunge();
LOG.debug("Deleting non-present media files...");
mediaFileDao.expunge();
LOG.debug("Database cleanup complete.");
mediaFileDao.checkpoint();
} else {
LOG.warn("Missing index statistics - index probably hasn't been created yet. Not expunging index.");
LOG.warn("Index hasn't been created yet or during scanning. Plese execute clean up after scan is completed.");
}
LOG.debug("Cleaning database...");
LOG.debug("Deleting non-present artists...");
artistDao.expunge();
LOG.debug("Deleting non-present albums...");
albumDao.expunge();
LOG.debug("Deleting non-present media files...");
mediaFileDao.expunge();
LOG.debug("Database cleanup complete.");
mediaFileDao.checkpoint();
}
private List<MusicFolderSettingsCommand.MusicFolderInfo> wrap(List<MusicFolder> musicFolders) {

@ -313,8 +313,10 @@ public class IndexManager {
}
} catch (IndexNotFoundException e) {
LOG.debug("Index {} does not exist in {}, likely not yet created.", indexType.toString(), indexDirectory.getAbsolutePath());
return null;
} catch (IOException e) {
LOG.warn("Failed to initialize SearcherManager.", e);
return null;
}
}
try {

Loading…
Cancel
Save