Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection string parameters InitialSize and Password are incompatible #929

Closed
spodskubka opened this issue Mar 6, 2018 · 3 comments
Closed

Comments

@spodskubka
Copy link

spodskubka commented Mar 6, 2018

This may be by design, but i haven't found it documented anywhere, so I am reporting this as an issue.

The following code uses LiteDB 4.1.1 and demonstrates the issue:

using System;
using System.IO;
using LiteDB;

class Poco
{
    public Guid Id { get; set; }
    public string Text { get; set; }
}

class Program
{
    static void Main()
    {
        var connectionString = new ConnectionString("test.litedb")
        {
            Password = "password",
            InitialSize = 50 * 1024 * 1024,
        };

        File.Delete("test.litedb");
        using (var liteDatabase = new LiteDatabase(connectionString))
        {
            LiteCollection<Poco> pocoCollection = liteDatabase.GetCollection<Poco>();
            pocoCollection.EnsureIndex(poco => poco.Text);
        }
    }
}

This is the exception that is happening in the call to EnsureIndex():

LiteDB.LiteException: Datafile is not a LiteDB database.
   at LiteDB.HeaderPage.ReadContent(ByteReader reader)
   at LiteDB.BasePage.ReadPage(Byte[] buffer)
   at LiteDB.PageService.GetPage[T](UInt32 pageID)
   at LiteDB.PageService.NewPage[T](BasePage prevPage)
   at LiteDB.CollectionService.Add(String name)
   at LiteDB.LiteEngine.GetCollectionPage(String name, Boolean addIfNotExits)
   at LiteDB.LiteEngine.Transaction[T](String collection, Boolean addIfNotExists, Func`2 action)
   at LiteDB.LiteEngine.EnsureIndex(String collection, String field, String expression, Boolean unique)
   at LiteDB.LiteCollection`1.EnsureIndex(String field, String expression, Boolean unique)
   at LiteDB.LiteCollection`1.EnsureIndex[K](Expression`1 property, Boolean unique)
   at Program.Main() in Program.cs:line 25

My guess is

  • the pages that are written initially in response to the InitialSize property are not being encrypted
  • subsequent attempts to read these pages use decryption and thus return invalid data
@mbdavid
Copy link
Collaborator

mbdavid commented Mar 6, 2018

Hi @spodskubka, you are absolute right. As I read issue title I get same idea: initial size create pages with no encryption... and this can b viewed here:

https://github.com/mbdavid/LiteDB/blob/master/LiteDB/Engine/LiteEngine.cs#L279

Thanks, I will fix soo (it's just add encrypt method call)

@mbdavid mbdavid added the bug label Mar 6, 2018
@spodskubka
Copy link
Author

Any performance concerns when writing 50 MB of encrypted vs. unencrypted empty pages?
Since AES is used that shouldn't be an issue, right?

@mbdavid
Copy link
Collaborator

mbdavid commented Mar 6, 2018

There is not big difference between encrypted vs. unencrypted performance (~10%). I made a test (in v3) using different operations with/without encryption. You can see times here:

https://github.com/mbdavid/LiteDB-Perf

mbdavid added a commit that referenced this issue Mar 10, 2018
@mbdavid mbdavid added the fixed label Mar 10, 2018
github-actions bot pushed a commit to Reddevildragg-UPM-Forks/LiteDB that referenced this issue Nov 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants