Skip to content
Permalink
Browse files

Merge pull request #434 from longfin/feature/litedb-readonly

Add readOnly option to LiteDBStore
  • Loading branch information...
longfin committed Aug 13, 2019
2 parents 993d9c3 + 7d8670d commit 2fe236d8c58cd9897eb121d036a408910ffed050
Showing with 12 additions and 2 deletions.
  1. +3 −0 CHANGES.md
  2. +9 −2 Libplanet/Store/LiteDBStore.cs
@@ -17,6 +17,8 @@ To be released.
- `ActionEvaluation.Action` became to `IAction` type. [[#319], [#367]]
- `LiteDBStore()` constructor became to have a new option named `flush` and
turned on by default. [[#387], [LiteDB #1268]]
- `LiteDBStore()` constructor became to have a new option named `readOnly` and
turned off by default. [[#434]]
- `BaseIndex.ContainsKey()` method became `abstract`. [[#390]]
- `BlockDownloadState.TotalBlockCount` and `BlockDownloadState.ReceivedBlockCount`
became to `Int64` type. [[#396], [#399]]
@@ -141,6 +143,7 @@ To be released.
[#423]: https://github.com/planetarium/libplanet/pull/423
[#424]: https://github.com/planetarium/libplanet/pull/424
[#426]: https://github.com/planetarium/libplanet/pull/426
[#434]: https://github.com/planetarium/libplanet/pull/434
[LiteDB #1268]: https://github.com/mbdavid/LiteDB/issues/1268
[floating-point determinism]: https://wp.me/p1fTCO-kT

@@ -50,11 +50,14 @@ public class LiteDBStore : BaseStore, IDisposable
/// <param name="cacheSize">Max number of pages in the cache.</param>
/// <param name="flush">Writes data direct to disk avoiding OS cache. Turned on by default.
/// </param>
/// <param name="readOnly">Opens database readonly mode. Turned off by default.
/// </param>
public LiteDBStore(
string path,
bool journal = true,
int cacheSize = 50000,
bool flush = true
bool flush = true,
bool readOnly = false
)
{
if (path is null)
@@ -72,7 +75,11 @@ public class LiteDBStore : BaseStore, IDisposable
Flush = flush,
};

if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) &&
if (readOnly)
{
connectionString.Mode = LiteDB.FileMode.ReadOnly;
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) &&
Type.GetType("Mono.Runtime") is null)
{
// macOS + .NETCore doesn't support shared lock.

0 comments on commit 2fe236d

Please sign in to comment.
You can’t perform that action at this time.