mbdavid / LiteDB

LiteDB - A .NET NoSQL Document Store in a single data file
http://www.litedb.org
MIT License
8.58k stars 1.25k forks source link

[BUG] Old -log.litedb files cause bugs on migration. #2048

Open agreentejada opened 3 years ago

agreentejada commented 3 years ago

Version 5.0.11

Describe the bug Migrating for 5.0.9 to 5.0.11 causes a System.IO.IOException: There is not enough space on the disk. error. This issue can be fixed by delete old -log.litedb files.

In the class I wrote below, this error came up when I was attempting ModelDB.GetIDs().

Code to Reproduce

//I've simplified my DTO model and Connector class below. For security purposes, I have omitted all but the relevant code.
public class Model
{
    [BsonId]
    public int ID { get; set; }
    public string Data { get; set; }
}

public static class ModelDB
{
    //The single DB instance for all later operations.
    private static LiteDatabase DB;

    static ModelDB()
    {
        DB = Connector.Connect(Connector.LiteDBType.Model);
    }

    //Generic close function in case the DB needs to be prematurely reset.
    public static void Close(bool reset = false)
    {
        DB.Dispose();

        if (reset)
        {
            DB = Connector.Connect(Connector.LiteDBType.Model);
        }
    }
    public static int[] GetIDs()
    {
        var col = DB.GetCollection<Model>("models");
        return col.FindAll().Select(X => X.ID).ToArray();
    }
}

If necessary, here's the Connector class.

public static class Connector
    {
        static string dbpath = Path.Combine(FilePaths.RootFolder, "LiteDB");
        static readonly string modelspath = Path.Combine(dbpath, "Models.litedb");

        static Connector()
        {
            Directory.CreateDirectory(dbpath);
        }

        public enum LiteDBType
        {
           Models
        }

        public static LiteDatabase Connect(LiteDBType type, BsonMapper mapper = null)
        {
            string path = string.Empty;
            switch (type)
            {
                case LiteDBType.Models:
                    path = modelspath
                    break;
                default:
                    break;
            }

            var connection = new ConnectionString()
            {
                Filename = path,
                Upgrade = true,
            };

            return new LiteDatabase(connection, mapper);
        }
    }

Expected behavior I did not expect any significant difference between V5.0.9 and V5.0.11. I had initially upgraded by repo to address #1656.

Screenshots/Stacktrace ENSURE error

Additional context Add any other context about the problem here.

lbnascimento commented 3 years ago

@agreentejada Could you send me the datafile and the logfile? You can send them to lbnascimento@inf.ufrgs.br

agreentejada commented 3 years ago

Unfortunately, the bug was on a business sensitive application, so I just deleted all the -log.litedb files. I haven't been able to reproduce the bug with other caches. Since this is pretty niche, feel free to close this issue.