Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Bobris/BTDB
Browse files Browse the repository at this point in the history
  • Loading branch information
Bobris committed Jun 3, 2014
2 parents a8718ee + 2d67cf6 commit d502c54
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
12 changes: 6 additions & 6 deletions BTDB/EventStoreLayer/AppendingEventStore.cs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void SerializeIntoBuffer(object metadata, IReadOnlyList<object> events, out int
out IDescriptorSerializerContext serializerContext, out BlockType blockType, out IDescriptorSerializerContext serializerContext, out BlockType blockType,
out int lenWithoutEndPadding, out ByteBuffer block) out int lenWithoutEndPadding, out ByteBuffer block)
{ {
startOffset = (int) EndBufferLen + HeaderSize; startOffset = (int)EndBufferLen + HeaderSize;
var writer = new ByteBufferWriter(); var writer = new ByteBufferWriter();
writer.WriteBlock(_zeroes, 0, startOffset); writer.WriteBlock(_zeroes, 0, startOffset);
serializerContext = Mapping; serializerContext = Mapping;
Expand Down Expand Up @@ -95,16 +95,16 @@ void SerializeIntoBuffer(object metadata, IReadOnlyList<object> events, out int
} }
else else
{ {
writer.WriteVUInt32((uint) events.Count); writer.WriteVUInt32((uint)events.Count);
foreach (var o in events) foreach (var o in events)
{ {
serializerContext.StoreObject(writer, o); serializerContext.StoreObject(writer, o);
} }
blockType |= BlockType.HasMoreEvents; blockType |= BlockType.HasMoreEvents;
} }
} }
lenWithoutEndPadding = (int) writer.GetCurrentPosition(); lenWithoutEndPadding = (int)writer.GetCurrentPosition();
writer.WriteBlock(_zeroes, 0, (int) (SectorSize - 1)); writer.WriteBlock(_zeroes, 0, (int)(SectorSize - 1));
block = writer.Data; block = writer.Data;
if (CompressionStrategy.ShouldTryToCompress(lenWithoutEndPadding - startOffset)) if (CompressionStrategy.ShouldTryToCompress(lenWithoutEndPadding - startOffset))
{ {
Expand All @@ -114,7 +114,7 @@ void SerializeIntoBuffer(object metadata, IReadOnlyList<object> events, out int
blockType |= BlockType.Compressed; blockType |= BlockType.Compressed;
Array.Copy(compressedBlock.Buffer, compressedBlock.Offset, block.Buffer, startOffset, compressedBlock.Length); Array.Copy(compressedBlock.Buffer, compressedBlock.Offset, block.Buffer, startOffset, compressedBlock.Length);
lenWithoutEndPadding = startOffset + compressedBlock.Length; lenWithoutEndPadding = startOffset + compressedBlock.Length;
Array.Copy(_zeroes, 0, block.Buffer, lenWithoutEndPadding, (int) SectorSize - 1); Array.Copy(_zeroes, 0, block.Buffer, lenWithoutEndPadding, (int)SectorSize - 1);
} }
} }
} }
Expand Down Expand Up @@ -146,7 +146,7 @@ public void FinalizeStore()
var startOffset = (int)EndBufferLen + HeaderSize; var startOffset = (int)EndBufferLen + HeaderSize;
if (EndBufferPosition + (ulong)startOffset <= File.MaxFileSize) if (EndBufferPosition + (ulong)startOffset <= File.MaxFileSize)
{ {
WriteOneBlock(ByteBuffer.NewSync(new byte[SectorSize + HeaderSize], startOffset, 0), BlockType.LastBlock); WriteOneBlock(ByteBuffer.NewSync(new byte[SectorSize * 2], startOffset, 0), BlockType.LastBlock);
} }
EndBufferPosition = ulong.MaxValue; EndBufferPosition = ulong.MaxValue;
KnownAsFinished = true; KnownAsFinished = true;
Expand Down
14 changes: 14 additions & 0 deletions BTDBTest/EventStoreTest.cs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@ public void CanFinalizeEventStoreAfterReadFromStart()
Assert.False(appender.IsKnownAsFinished()); Assert.False(appender.IsKnownAsFinished());
} }


[Test]
public void CanFinalizeEventStoreOnEverySectorPosition()
{
for (int i = 4000; i < 4600; i++)
{
var manager = new EventStoreManager();
manager.CompressionStrategy = new NoCompressionStrategy();
var file1 = new MemoryEventFileStorage(4096, 8192);
var appender = manager.AppendToStore(file1);
appender.Store(null, new object[] { new byte[i] });
appender.Store(null, new object[] { new byte[7000] });
}
}

[Test] [Test]
public void CanFinalizeEventStoreAfterReadFromStartFirstNearlyFull() public void CanFinalizeEventStoreAfterReadFromStartFirstNearlyFull()
{ {
Expand Down

0 comments on commit d502c54

Please sign in to comment.