public OpDataPersister(OplogConfig config) { _config = config; Segments = Directory .GetFiles(Path.Combine(_config.BasePath, "."), string.Format("{0}*.sf", _config.Name)) .Select(x => ColdSegment.Load(x, _config.Name)) .OrderBy(x => x.Position) .ToList(); if(!Segments.Any()) RollNewSegment(); else { var last = Segments.Last(); var blocks = last.FetchForward().ToList(); Console.WriteLine("Last [{0}] {1}", last.Position, blocks.Count()); last.Dispose(); Segments.Remove(last); var burner = new HotSegmentBurner(_config, last.Position); CurrentSegment = new HotSegment(_config.Quota, blocks) { Burner = burner, Position = last.Position }; Segments.Add(CurrentSegment); } }
public void AppendBeforeReachingMaxCapacityTest() { var activeSegment = new HotSegment(45 * Units.MEGA) { Burner = new HotSegmentBurner(QuotedAs(45 * Units.MEGA), 0), }; for (var i = 0; i < 10 * 100; i++) { var next = Guid.NewGuid().ToByteArray(); activeSegment.Append(next); } Assert.That(activeSegment.Blocks.Count, Is.EqualTo(11)); // blocks Assert.That((10752 * 4 * Units.KILO) / Units.MEGA, Is.EqualTo(42)); // mb }
public void AppendStopsAtMaxCapacityTest() { var activeSegment = new HotSegment(10 * Units.KILO) { Burner = new HotSegmentBurner(QuotedAs(10 * Units.KILO), 0), }; ; try { for (var i = 0; i < 10 * 100; i++) { var next = Guid.NewGuid().ToByteArray(); activeSegment.Append(next); } } catch (HotSegmentFullException) { } Assert.That(activeSegment.Blocks.Count, Is.EqualTo(2)); Assert.That(activeSegment.Blocks.Select(x => x.Payload.Length).Sum() / Units.KILO, Is.EqualTo(8)); }
private void RollNewSegment() { if (CurrentSegment != null) CurrentSegment.Burner.Dispose(); var position = Segments.Count * _config.Quota; CurrentSegment = new HotSegment(_config.Quota) { Burner = new HotSegmentBurner(_config, position), Position = position }; Segments.Add(CurrentSegment); }