public void Dispose() { if (mWriteAheadLogWriter != null) { mWriteAheadLogWriter.Dispose(); mWriteAheadLogWriter = null; } }
public void CreateSnapshot(string snapshotPath) { if (File.Exists(snapshotPath)) { throw new ArgumentException(string.Format("Snapshot file already exists: {0}", snapshotPath)); } using (var writer = new WriteAheadLogWriter(snapshotPath)) { foreach (var kv in mDictionary) { writer.Append((byte)WriteAheadLogType.Add, Encoding.UTF8.GetBytes(kv.Key), kv.Value); } } }
public PersistentDictionary(string snapshotPath) { SnapshotPath = snapshotPath; if (File.Exists(TempSnapshotPath) && !File.Exists(SnapshotPath)) { File.Move(TempSnapshotPath, SnapshotPath); } mDictionary = LoadSnapshot(SnapshotPath); mWriteAheadLogWriter = new WriteAheadLogWriter(SnapshotPath); if (mWriteAheadLogWriter.Length > 0) { CheckPoint(); } }
public void CheckPoint() { if (File.Exists(TempSnapshotPath)) { File.Delete(TempSnapshotPath); } CreateSnapshot(TempSnapshotPath); mWriteAheadLogWriter.Dispose(); File.Delete(SnapshotPath); File.Move(TempSnapshotPath, SnapshotPath); mWriteAheadLogWriter = new WriteAheadLogWriter(SnapshotPath); }