From e635055bf6f6e73dc43ecb1c8204f652533e713c Mon Sep 17 00:00:00 2001 From: tesshucom Date: Tue, 25 Feb 2020 10:34:06 +0900 Subject: [PATCH] Fix not to perform clean up during scan (#1550) --- .../MusicFolderSettingsController.java | 40 ++++++++++++------- .../player/service/search/IndexManager.java | 2 + 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/airsonic-main/src/main/java/org/airsonic/player/controller/MusicFolderSettingsController.java b/airsonic-main/src/main/java/org/airsonic/player/controller/MusicFolderSettingsController.java index 7182f133..718f1ce1 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/controller/MusicFolderSettingsController.java +++ b/airsonic-main/src/main/java/org/airsonic/player/controller/MusicFolderSettingsController.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 wrap(List musicFolders) { diff --git a/airsonic-main/src/main/java/org/airsonic/player/service/search/IndexManager.java b/airsonic-main/src/main/java/org/airsonic/player/service/search/IndexManager.java index 27525ac6..c4e9f551 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/service/search/IndexManager.java +++ b/airsonic-main/src/main/java/org/airsonic/player/service/search/IndexManager.java @@ -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 {