Re: Old Lucene Index Directories Not Being Deleted

Dawid Weiss <[email protected]> Wed, 17 Dec 2025 20:44:33 +0100
Newsgroups gmane.comp.jakarta.lucene.user
Message-ID <CAM21Rt9tPnns6aGi6aauEO_22i6MdCew=-rqyBLt6gz8v7A2Hg@mail.gmail.com>
--00000000000063e5f506462b145b
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Your application very likely doesn't close opened index readers/
directories properly and open file handles keep those files un-removable in
(older) Windows versions. If you clean up properly, all file handles should
be closed. Also - don't delete those files manually, they will get deleted
automatically when new index commits are made and when nothing holds those
files.

Dawid

On Wed, Dec 17, 2025 at 7:02=E2=80=AFPM Parth Tyagi <[email protected]> wrot=
e:

> Hello,
> On Rebuilding Lucene Indexes, a new directory is created and connections
> to old directories are closed. But, when logic to delete old directories =
is
> called -> it fails with Exception:
> Caused by: java.nio.file.AccessDeniedException:
> C:\example-1\example-2\index\example-3-1\example-4\index_folder__20251216=
1121\_0.fdt
> at
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsExcep=
tion.java:89)
> at
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsExcepti=
on.java:103)
> at
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsExcepti=
on.java:108)
> at
> java.base/sun.nio.fs.WindowsFileSystemProvider.implDelete(WindowsFileSyst=
emProvider.java:273)
> at
> java.base/sun.nio.fs.AbstractFileSystemProvider.deleteIfExists(AbstractFi=
leSystemProvider.java:109)
> at java.base/java.nio.file.Files.deleteIfExists(Files.java:1191)
> at
> org.apache.commons.io.file.DeletingPathVisitor.visitFile(DeletingPathVisi=
tor.java:158)
> at
> org.apache.commons.io.file.DeletingPathVisitor.visitFile(DeletingPathVisi=
tor.java:37)
> at java.base/java.nio.file.Files.walkFileTree(Files.java:2786)
> at java.base/java.nio.file.Files.walkFileTree(Files.java:2857)
> at org.apache.commons.io.file.PathUtils.visitFileTree(PathUtils.java:1845=
)
> at org.apache.commons.io.file.PathUtils.deleteDirectory(PathUtils.java:59=
7)
> at org.apache.commons.io.file.PathUtils.delete(PathUtils.java:556)
> at org.apache.commons.io.FileUtils.forceDelete(FileUtils.java:1421)
>
> This is what I have tried so far :
>
> Tried following things to delete old directory after rebuilding:
>
>   1.
> Observed reference of searcher manager in heap dump, so made changes to
> remove searcher in {package}.{class}#setIndexDirectoryAndWriterTuple, but
> after changes directories were not deleted. Observed heap dump after
> removing searcher manager reference, in heap dump reference was removed b=
ut
> directory was not deleted.
>   2.
> Tried refresh and release searcher.
>   3.
> Added retries to delete directories in
> com.{package}.FileUtils#deleteFolder. It never works consistently or on a
> consistent time frame. The period can vary from 20-50 minutes when it wor=
ks
> or never working even after 2-3 hours.
>   4.
> Closed index writer just before deleting directory in
> {package}.LuceneDirectoryDeleter#deleteDirectory(org.apache.lucene.store.=
FSDirectory).(Directories
> for 1-2 indexes were deleted but not for others).
>   5.
> Tried deleting old directory with unit test and directory was deleted
> successfully and issue was not reproducible through unit test.
>   6.
> Tried obtainLock() method of Lock class in lucene store to identify if an=
y
> lock is already obtained on the directory but lock is successfully obtain=
ed
> without any exception.
>
> Can you help with this ?
>
> Thanks,
> Parth.
>
>
> Get Outlook for Mac <https://aka.ms/GetOutlookForMac>
>

--00000000000063e5f506462b145b--