public void Truncate()
        {
            if (!IsFragmented) return;

            _mode = MaintenanceMode.Lockdown;
            _lock.EnterExclusive();
            try
            {
                using (var memoryStore = new MemoryBinaryStore())
                {
                    var entries = _fragment.TableOfContent.Entries;
                    var memoryEntries = new List<Entry>();

                    foreach (var entry in entries)
                    {
                        var content = _service.GetContent(entry);
                        long storeOffset;
                        if (!memoryStore.TryWrite(content, out storeOffset))
                            throw new MaintenanceException("Failed to write data block to memory store, " + entry.Key.ToString());

                        memoryEntries.Add(new Entry
                        {
                            Key = entry.Key,
                            ValueLength = content.Length,
                            ValueOffset = storeOffset + 16
                        });
                    }
                    byte[] tableOfContent;
                    using (var stream = new MemoryStream())
                    {
                        var converter = new EntryBinaryConverter();
                        foreach (var entry in memoryEntries)
                            converter.ConvertTo(entry, stream);

                        tableOfContent = stream.ToArray();
                    }
                    var data = memoryStore.ToArray();
                    _service.ApplyTruncatedData(tableOfContent, data);

                }
            }
            finally
            {
                _mode = MaintenanceMode.Normal;
                _lock.ExitExclusive();
            }
        }
Beispiel #2
0
        public void AddEntityTest()
        {
            var context = CreateTarget();

            var car = new Car {
                RegistrationNumber = "AAA000",
                Nationality = Nationality.Sweden
            };

            context.Index.Storage.Add(new StringKey(car.RegistrationNumber), car);
            context.Index.CommitModifications();

            var actual = context.Index.Match(CompareOperation.Equal, (int)Nationality.Sweden).ToList();
            Assert.AreEqual(1, actual.Count);
            Assert.AreEqual(new StringKey(car.RegistrationNumber), actual.First());

            var store = new MemoryBinaryStore(context.Store.ToArray());
            context = CreateTarget(store);

            actual = context.Index.Match(CompareOperation.Equal, (int)Nationality.Sweden).ToList();
            Assert.AreEqual(1, actual.Count);
            Assert.AreEqual(new StringKey(car.RegistrationNumber), actual.First());
        }
Beispiel #3
0
 private TestContext CreateTarget()
 {
     var store = new MemoryBinaryStore();
     return CreateTarget(store);
 }
Beispiel #4
0
 private TestContext CreateTarget(MemoryBinaryStore store)
 {
     var configuration = new IndexConfiguration {
         EntityType = typeof (Car),
         Type = typeof (int),
         UniqueName = "Nationality"
     };
     var storage = new IndexStorage<int>(store, configuration);
     storage.Initialize();
     var index = new TableIndex<int>(storage, new ComparableIndexAlgorithm<int>());
     return new TestContext {Store = store, Index = index};
 }