Skip to content

Commit

Permalink
Fix journal initial position
Browse files Browse the repository at this point in the history
  • Loading branch information
mbdavid committed Jul 2, 2017
1 parent 139fdff commit cb53709
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
30 changes: 15 additions & 15 deletions LiteDB.Tests/Concurrency/ProcessTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,24 @@ public void Process_Insert_Test()
dbA.EnsureIndex("col", "process", false);

// insert 1000 x instance=1
//var ta = Task.Factory.StartNew(() =>
//{
for (var i = 0; i < 1000; i++)
{
dbA.Insert("col", new BsonDocument { { "process", 1 } });
}
//});
var ta = Task.Factory.StartNew(() =>
{
for (var i = 0; i < 1000; i++)
{
dbA.Insert("col", new BsonDocument { { "process", 1 } });
}
});

// insert 700 x instance=2
//var tb = Task.Factory.StartNew(() =>
//{
for (var i = 0; i < 700; i++)
{
dbB.Insert("col", new BsonDocument { { "process", 2 } });
}
//});
var tb = Task.Factory.StartNew(() =>
{
for (var i = 0; i < 700; i++)
{
dbB.Insert("col", new BsonDocument { { "process", 2 } });
}
});

//Task.WaitAll(ta, tb);
Task.WaitAll(ta, tb);

Assert.AreEqual(1000, dbA.Count("col", Query.EQ("process", 1)));
Assert.AreEqual(700, dbA.Count("col", Query.EQ("process", 2)));
Expand Down
2 changes: 1 addition & 1 deletion LiteDB/Engine/Disks/FileDiskService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public void WriteJournal(ICollection<byte[]> pages, uint lastPageID)
BasePage.GetSizeOfPages(pages.Count));

// go to initial file position (after lastPageID)
_stream.Seek(lastPageID + 1, SeekOrigin.Begin);
_stream.Seek(BasePage.GetSizeOfPages(lastPageID + 1), SeekOrigin.Begin);

foreach(var buffer in pages)
{
Expand Down
2 changes: 1 addition & 1 deletion LiteDB/Engine/Engine/Find.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public partial class LiteEngine
/// <summary>
/// Find for documents in a collection using Query definition
/// </summary>
public IEnumerable<BsonDocument> Find(string collection, Query query, int skip = 0, int limit = int.MaxValue, int bufferSize = 10)
public IEnumerable<BsonDocument> Find(string collection, Query query, int skip = 0, int limit = int.MaxValue)
{
if (collection.IsNullOrWhiteSpace()) throw new ArgumentNullException("collection");
if (query == null) throw new ArgumentNullException("query");
Expand Down
8 changes: 4 additions & 4 deletions LiteDB/Engine/Services/LockService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public LockControl Shared()
}

// try enter in read mode
if (_thread.TryEnterReadLock(_timeout))
if (!_thread.TryEnterReadLock(_timeout))
{
throw LiteException.LockTimeout(_timeout);
}
Expand Down Expand Up @@ -91,15 +91,15 @@ public LockControl Exclusive()
{
lock (_disk)
{
// if are locked in shared, throw invalid operation
if (_state == LockState.Shared) throw new InvalidOperationException("Call exit shared lock before call exclusive");

// if already in exclusive, do nothing
if (_state == LockState.Exclusive)
{
return new LockControl(() => { });
}

// if are locked in shared, exit read to enter in write
if (_state == LockState.Shared) throw new NotSupportedException("Lock are in exclusive mode");

// try enter in write mode (thread)
if (!_thread.TryEnterWriteLock(_timeout))
{
Expand Down

0 comments on commit cb53709

Please sign in to comment.