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

Add readOnly option to LiteDBStore #434

Merged
merged 1 commit into from Aug 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.md
Expand Up @@ -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]]
Expand Down Expand Up @@ -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

Expand Down
11 changes: 9 additions & 2 deletions Libplanet/Store/LiteDBStore.cs
Expand Up @@ -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)
Expand All @@ -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.
Expand Down