コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        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);
        }