コード例 #1
0
ファイル: JournaledMemTable.cs プロジェクト: T145/archive
        public JournaledMemTable(string baseFileName, int version)
        {
            _baseFileName = baseFileName;
            _version      = version;
            _memTable     = new MemTable();

            // If the journal exists from a previous run, then load its data into the memtable.
            string journalFile = Config.JournalFile(baseFileName, version);

            if (File.Exists(journalFile))
            {
                var journalReader = new JournalReader(baseFileName, version);
                try {
                    foreach (var pair in journalReader.Enumerate())
                    {
                        _memTable.Add(pair.Key, pair.Value);
                    }
                } finally {
                    journalReader.Close();
                }
                _journal = new JournalWriter(baseFileName, version, true);
            }
            else
            {
                _journal = new JournalWriter(baseFileName, version, false);
            }
        }
コード例 #2
0
ファイル: JournalTests.cs プロジェクト: T145/razordbx
        public void ReadAndWriteJournalFile()
        {
            string path = Path.GetFullPath ("TestData\\RWJournal");
            if (!Directory.Exists (path)) Directory.CreateDirectory (path);

            JournalWriter jw = new JournalWriter (path, 324, false);

            List<KeyValuePair<Key, Value>> items = new List<KeyValuePair<Key, Value>> ();
            for (int i = 0; i < 10000; i++) {
                Key randKey = Key.Random (20);
                Value randValue = Value.Random (100);
                jw.Add (randKey, randValue);
                items.Add (new KeyValuePair<Key, Value> (randKey, randValue));
            }
            jw.Close ();

            JournalReader jr = new JournalReader (path, 324);
            int j = 0;
            foreach (var pair in jr.Enumerate()) {
                Assert.AreEqual (items [j].Key, pair.Key);
                Assert.AreEqual (items [j].Value, pair.Value);
                j++;
            }
            jr.Close ();
        }
コード例 #3
0
ファイル: MemTable.cs プロジェクト: T145/archive
 public void ReadFromJournal(string fileName, int version)          // Reads from the journal.
 {
     lock (_tableLock) {
         JournalReader jr = new JournalReader(fileName, version);
         try {
             foreach (var pair in jr.Enumerate())
             {
                 Add(pair.Key, pair.Value);
             }
         } finally {
             jr.Close();
         }
     }
 }
コード例 #4
0
ファイル: JournaledMemTable.cs プロジェクト: T145/razordbx
        public JournaledMemTable(string baseFileName, int version)
        {
            _baseFileName = baseFileName;
            _version = version;
            _memTable = new MemTable ();

            // If the journal exists from a previous run, then load its data into the memtable.
            string journalFile = Config.JournalFile (baseFileName, version);
            if (File.Exists (journalFile)) {
                var journalReader = new JournalReader (baseFileName, version);
                try {
                    foreach (var pair in journalReader.Enumerate()) {
                        _memTable.Add (pair.Key, pair.Value);
                    }
                } finally {
                    journalReader.Close ();
                }
                _journal = new JournalWriter (baseFileName, version, true);
            } else
                _journal = new JournalWriter (baseFileName, version, false);
        }
コード例 #5
0
ファイル: MemTable.cs プロジェクト: T145/razordbx
 // Reads from the journal.
 public void ReadFromJournal(string fileName, int version)
 {
     lock (_tableLock) {
         JournalReader jr = new JournalReader (fileName, version);
         try {
             foreach (var pair in jr.Enumerate())
                 Add (pair.Key, pair.Value);
         } finally {
             jr.Close ();
         }
     }
 }
コード例 #6
0
ファイル: JournalTests.cs プロジェクト: T145/razordbx
        public void ReadCorruptedJournalFile()
        {
            string path = Path.GetFullPath ("TestData\\ReadCorruptedJournal");
            if (!Directory.Exists (path)) Directory.CreateDirectory (path);

            JournalWriter jw = new JournalWriter (path, 324, false);

            List<KeyValuePair<Key, Value>> items = new List<KeyValuePair<Key, Value>> ();
            for (int i = 0; i < 10; i++) {
                Key randKey = Key.Random (20);
                Value randValue = Value.Random (100);
                jw.Add (randKey, randValue);
                items.Add (new KeyValuePair<Key, Value> (randKey, randValue));
            }
            jw.Close ();

            // Reopen the file and add a partial record
            var fileName = Config.JournalFile (path, 324);
            var writer = new BinaryWriter (new FileStream (fileName, FileMode.Append, FileAccess.Write, FileShare.None, 1024, false));
            Key key = Key.Random (20);
            writer.Write7BitEncodedInt (key.Length);
            writer.Write (key.InternalBytes);
            writer.Write7BitEncodedInt (0);
            writer.Flush ();
            writer.Close ();

            JournalReader jr = new JournalReader (path, 324);
            int j = 0;
            foreach (var pair in jr.Enumerate()) {
                Assert.AreEqual (items [j].Key, pair.Key);
                Assert.AreEqual (items [j].Value, pair.Value);
                j++;
            }
            jr.Close ();
        }