Litedb: [QUESTION] Using Memory Stream in v5

Created on 13 Feb 2020  路  4Comments  路  Source: mbdavid/LiteDB

Hi,

With migration to v5 there are some breaking changes (there is no Shrink method, no access to Engine etc) and there is no documentation how to migrate from v4.
In v4, I used MemoryStream to load data from file and pass it to the LiteRepository, and after when I finished working with LiteDB I was saving the MemoryStream to disk as byte array in a file. And afterwards when reloading the MemoryStream from the file, the LiteDB contained my objects.
Now, it seems that MemoryStream does not contains all data necessary to recreate the LiteRepository the next time when it is reloaded from disk. The way that is used to use LiteDB is not longer valid?

How can I retrieve the Data that is stored in the LiteRepository (initialized by MemoryStream) and save it on disk?

question

All 4 comments

LiteDB v5 works quit different from v4 in this aspect. In v4 you had a single file only (with no temp data). v5 needs temp (log file) to implement WAL. When you initialize a database with MemoryStream, another memory stream are created to store data log (pages changes). This new memory stream contains changes only and when get 1000 pages, this file are copied into original data file. This command can be called by Checkpoint method too. After a checkpoint, your datafile contains all your data an log file are clear. This checkpoin also occurs when you close database.

Given I create a database instance A using

    public LiteDatabase(Stream stream, BsonMapper mapper = null)

Is that correct that I should not open another database instance B using the same stream until I close A? (Because, my thinking, A and B will create different WAL streams instead of using the same).

Hi @mbdavid thanks for the explanation.
With the Checkpoint() method, my use case works well again.

Hi @Soruk , I'm closing this issue as I believe it has been resolved. If it isn't the case, please reopen this issue :slightly_smiling_face:

Was this page helpful?
0 / 5 - 0 ratings