Пример #1
0
 public void Dispose()
 {
     if (mWriteAheadLogWriter != null)
     {
         mWriteAheadLogWriter.Dispose();
         mWriteAheadLogWriter = null;
     }
 }
Пример #2
0
        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);
                }
            }
        }
Пример #3
0
        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();
            }
        }
Пример #4
0
        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);
        }