Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Deleting Ain't Easy

DZone's Guide to

Deleting Ain't Easy

Free Resource

RavenDB vs MongoDB: Which is Better? This White Paper compares the two leading NoSQL Document Databases on 9 features to find out which is the best solution for your next project.  

We started getting test failures in Voron regarding being unable to clean up the data directory. Which was a major cause for concern. We thought that we had a handle leak, or something like that.

As it turned out, we could reproduce this issue with the following code:


 class Program
 {
     static void Main(string[] args)
     {
         var name = Guid.NewGuid().ToString();
         for (int i = 0; i < 1000; i++)
         {
             Console.WriteLine(i);
             Directory.CreateDirectory(name);
  
             for (int j = 0; j < 10; j++)
             {
                 File.WriteAllText(Path.Combine(name, "test-" +j), "test");
             }
  
             if (Directory.Exists(name))
                 Directory.Delete(name, true);
         }
         
     }
 }

If you run this code, in 6 out of 10 runs, it would fail with something like this:

I am pretty sure that the underlying cause is some low lever “thang” somewhere on my system. FS Indexing, AV, etc. But it basically means that directory delete is not atomic, and that I should basically just suck it up and write a robust delete routine that can handle failure and retry until it is successful.


Do you pay to use your database? What if your database paid you? Learn more with RavenDB.

Topics:

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}