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 HotSegmentBurner(OplogConfig cfg, long position) { Path = System.IO.Path.Combine(cfg.BasePath, string.Format("{0}{1}.sf", cfg.Name, position.ToString("D12"))); _fsSegment = new FileStream( Path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite, 4096, FileOptions.WriteThrough); if(cfg.Fixed) _fsSegment.SetLength(cfg.Quota); }
public virtual void SetUp() { var typeName = GetType().Name.Length > 30 ? GetType().Name.Substring(0, 30) : GetType().Name; Filename = string.Format("{0}-{1}", typeName, Guid.NewGuid()); Cfg4K = new OplogConfig() { Name = Filename, Quota = 4 * Units.KILO, Fixed = true, BasePath = "utt" }; Cfg4Mb = new OplogConfig() { Name = Filename, Quota = 4 * Units.MEGA, Fixed = true, BasePath = "utt" }; }
public Oplog(OplogConfig config) { Advanced = new OpDataPersister(config); }