Esempio n. 1
0
        public void CanAddMultiValuesUnderTheSameKeyToBatch()
        {
            using (var env = new StorageEnvironment(StorageEnvironmentOptions.CreateMemoryOnly()))
            {
                var rand       = new Random();
                var testBuffer = new byte[168];
                rand.NextBytes(testBuffer);

                CreateTrees(env, 1, "multitree");

                var batch = new WriteBatch();

                batch.MultiAdd("key", "value1", "multitree0");
                batch.MultiAdd("key", "value2", "multitree0");

                env.Writer.Write(batch);

                using (var tx = env.NewTransaction(TransactionFlags.Read))
                {
                    var tree = tx.Environment.State.GetTree(tx, "multitree0");
                    using (var it = tree.MultiRead("key"))
                    {
                        Assert.True(it.Seek(Slice.BeforeAllKeys));

                        Assert.Equal("value1", it.CurrentKey.ToString());
                        Assert.True(it.MoveNext());

                        Assert.Equal("value2", it.CurrentKey.ToString());
                    }
                }
            }
        }
Esempio n. 2
0
        public void CanProperlySnapshot()
        {
            using (var state = new PersistentState("self", StorageEnvironmentOptions.CreateMemoryOnly(), CancellationToken.None)
            {
                CommandSerializer = new JsonCommandSerializer()
            })
            {
                state.UpdateTermTo(null, 1);
                state.AppendToLeaderLog(new NopCommand());
                for (int i = 0; i < 5; i++)
                {
                    state.AppendToLeaderLog(new DictionaryCommand.Set
                    {
                        Key   = i.ToString(),
                        Value = i
                    });
                }

                state.MarkSnapshotFor(6, 1, 5);

                state.AppendToLeaderLog(new DictionaryCommand.Set
                {
                    Key   = "1",
                    Value = 4
                });

                var lastLogEntry = state.LastLogEntry();

                Assert.Equal(7, lastLogEntry.Index);
            }
        }
Esempio n. 3
0
        public void CanQueryUsingSingleTerm()
        {
            using (var fullTextIndex = new FullTextIndex(StorageEnvironmentOptions.CreateMemoryOnly(), new DefaultAnalyzer()))
            {
                using (var indexer = fullTextIndex.CreateIndexer())
                {
                    indexer.NewIndexEntry();

                    indexer.AddField("Name", "Oren Eini");

                    indexer.AddField("Email", "*****@*****.**");

                    indexer.NewIndexEntry();

                    indexer.AddField("Name", "Arava Eini");

                    indexer.AddField("Email", "*****@*****.**");

                    indexer.Flush();
                }

                using (var searcher = fullTextIndex.CreateSearcher())
                {
                    Assert.Equal(1, searcher.Query(new TermQuery("Name", "oren")).Count());
                    Assert.Equal(0, searcher.Query(new TermQuery("Name", "rahien")).Count());
                }
            }
        }
Esempio n. 4
0
        public void CanQueryUsingBooleanQuery()
        {
            using (var fullTextIndex = new FullTextIndex(StorageEnvironmentOptions.CreateMemoryOnly(), new DefaultAnalyzer()))
            {
                using (var indexer = fullTextIndex.CreateIndexer())
                {
                    indexer.NewIndexEntry();

                    indexer.AddField("Name", "Oren");

                    indexer.AddField("Email", "*****@*****.**");

                    indexer.NewIndexEntry();

                    indexer.AddField("Name", "Oren");

                    indexer.AddField("Email", "*****@*****.**");

                    indexer.Flush();
                }

                using (var searcher = fullTextIndex.CreateSearcher())
                {
                    Assert.Equal(1, searcher.Query(new BooleanQuery(QueryOperator.And,
                                                                    new TermQuery("Name", "oren"),
                                                                    new TermQuery("Email", "*****@*****.**"))).Count());

                    Assert.Equal(2, searcher.Query(new BooleanQuery(QueryOperator.Or,
                                                                    new TermQuery("Name", "oren"),
                                                                    new TermQuery("Email", "*****@*****.**"))).Count());
                }
            }
        }
Esempio n. 5
0
        public void CanQueryWithInQuery()
        {
            using (var fullTextIndex = new FullTextIndex(StorageEnvironmentOptions.CreateMemoryOnly(), new DefaultAnalyzer()))
            {
                using (var indexer = fullTextIndex.CreateIndexer())
                {
                    indexer.NewIndexEntry();
                    indexer.AddField("Name", "David Boike");

                    indexer.NewIndexEntry();
                    indexer.AddField("Name", "Oren Eini");

                    indexer.NewIndexEntry();
                    indexer.AddField("Name", "Arava Eini");

                    indexer.NewIndexEntry();
                    indexer.AddField("Name", "Sean Epping");

                    indexer.NewIndexEntry();
                    indexer.AddField("Name", "Joe DeCock");

                    indexer.Flush();
                }

                using (var searcher = fullTextIndex.CreateSearcher())
                {
                    var results = searcher.QueryTop(new InQuery("Name", "joe", "epping", "boike"), 5);

                    Assert.Equal(3, results.Results.Length);
                }
            }
        }
        public unsafe void Scratch_file_is_aware_of_potentialy_active_readers()
        {
            var numberOfPages = 20;
            var handle        = NativeMemory.AllocateMemory(numberOfPages * Constants.Storage.PageSize);


            using (var env = StorageEnvironmentOptions.CreateMemoryOnly())
                using (var pager = env.CreateScratchPager("temp", 65 * 1024))
                    using (var file = new ScratchBufferFile(pager, 0))
                    {
                        Assert.False(file.HasActivelyUsedBytes(2));

                        file.Allocate(null, 1, 1);
                        file.Allocate(null, 1, 1);
                        file.Allocate(null, 1, 1);
                        file.Allocate(null, 1, 1);
                        file.Allocate(null, 1, 1);

                        file.Free(0, 1);
                        file.Free(1, 3);
                        file.Free(2, 4);
                        file.Free(3, 7);
                        file.Free(4, 9);

                        for (int i = 0; i <= 9; i++)
                        {
                            Assert.True(file.HasActivelyUsedBytes(i));
                        }

                        Assert.False(file.HasActivelyUsedBytes(10));
                        Assert.False(file.HasActivelyUsedBytes(20));
                    }
        }
Esempio n. 7
0
        public void AllScratchPagesShouldBeReleased()
        {
            var options = StorageEnvironmentOptions.CreateMemoryOnly();

            options.ManualFlushing = true;
            using (var env = new StorageEnvironment(options))
            {
                using (var txw = env.NewTransaction(TransactionFlags.ReadWrite))
                {
                    env.CreateTree(txw, "test");

                    txw.Commit();
                }

                using (var txw = env.NewTransaction(TransactionFlags.ReadWrite))
                {
                    var tree = txw.Environment.State.GetTree(txw, "test");

                    tree.Add("key/1", new MemoryStream(new byte[100]));
                    tree.Add("key/1", new MemoryStream(new byte[200]));
                    txw.Commit();
                }

                env.FlushLogToDataFile();                 // non read nor write transactions, so it should flush and release everything from scratch

                Assert.Equal(0, env.ScratchBufferPool.GetNumberOfAllocations(0));
            }
        }
Esempio n. 8
0
        public void IterationShouldNotFindAnyRecordsAndShouldNotThrowWhenNumberOfEntriesOnPageIs1AndKeyDoesNotMatch()
        {
            using (var env = new StorageEnvironment(StorageEnvironmentOptions.CreateMemoryOnly()))
            {
                using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
                {
                    env.CreateTree(tx, "tree");

                    tx.Commit();
                }

                using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
                {
                    var tree = tx.ReadTree("tree");
                    tree.Add(@"Raven\Database\1", StreamFor("123"));

                    tx.Commit();
                }

                using (var snapshot = env.CreateSnapshot())
                    using (var iterator = snapshot.Iterate("tree"))
                    {
                        Assert.False(iterator.Seek(@"Raven\Filesystem\"));
                    }
            }
        }
Esempio n. 9
0
        protected StorageTest()
        {
            DeleteDirectory(DataDir);
            _options = StorageEnvironmentOptions.CreateMemoryOnly();

            Configure(_options);
        }
Esempio n. 10
0
        public void ShouldWork()
        {
            using (var env = new StorageEnvironment(StorageEnvironmentOptions.CreateMemoryOnly()))
            {
                using (var tx = env.WriteTransaction())
                {
                    var s    = new string('0', 500);
                    var tree = tx.CreateTree("data");
                    for (int i = 0; i < 10; i++)
                    {
                        tree.Add("users-" + i + "-" + s, new byte[0]);
                    }
                    tx.Commit();
                }

                using (var tx = env.ReadTransaction())
                {
                    var tree = tx.ReadTree("data");
                    using (var it = tree.Iterate(false))
                    {
                        Slice key;
                        Slice.From(tx.Allocator, "users-7", out key);
                        Assert.True(it.Seek(key));

                        for (int i = 0; i < 10; i++)
                        {
                            Slice.From(tx.Allocator, "users-" + i, out key);
                            Assert.True(it.Seek(key), i.ToString());
                        }
                    }
                }
            }
        }
Esempio n. 11
0
        public void StorageEnvironment_CreateTree_Should_be_shipped_properly()
        {
            var transactionsToShip = new ConcurrentBag <TransactionToShip>();

            Env.Journal.OnTransactionCommit += tx =>
            {
                tx.CreatePagesSnapshot();
                transactionsToShip.Add(tx);
            };

            using (var tx = Env.NewTransaction(TransactionFlags.ReadWrite))
            {
                var tree = Env.CreateTree(tx, "TestTree");
                tree.Add("ABC", "Foo");
                tx.Commit();
            }

            using (var shippingDestinationEnv = new StorageEnvironment(StorageEnvironmentOptions.CreateMemoryOnly()))
            {
                foreach (var tx in transactionsToShip)
                {
                    shippingDestinationEnv.Journal.Shipper.ApplyShippedLog(tx.PagesSnapshot);
                }

                using (var snaphsot = shippingDestinationEnv.CreateSnapshot())
                {
                    Assert.DoesNotThrow(() =>                     //if tree doesn't exist --> throws InvalidOperationException
                    {
                        var result = snaphsot.Read("TestTree", "ABC");
                        Assert.Equal(1, result.Version);
                        Assert.Equal("Foo", result.Reader.ToStringValue());
                    });
                }
            }
        }
Esempio n. 12
0
        public ConfigurationStorage(DocumentDatabase db)
        {
            var path = db.Configuration.Core.DataDirectory.Combine("Configuration");

            var options = db.Configuration.Core.RunInMemory
                ? StorageEnvironmentOptions.CreateMemoryOnly(path.FullPath, db.Configuration.Storage.TempPath?.FullPath, db.IoChanges, db.CatastrophicFailureNotification)
                : StorageEnvironmentOptions.ForPath(path.FullPath, db.Configuration.Storage.TempPath?.FullPath, null, db.IoChanges, db.CatastrophicFailureNotification);

            options.OnNonDurableFileSystemError += db.HandleNonDurableFileSystemError;
            options.OnRecoveryError             += db.HandleOnRecoveryError;
            options.CompressTxAboveSizeInBytes   = db.Configuration.Storage.CompressTxAboveSize.GetValue(SizeUnit.Bytes);
            options.SchemaVersion                    = Constants.Schemas.ConfigurationVersion;
            options.ForceUsing32BitsPager            = db.Configuration.Storage.ForceUsing32BitsPager;
            options.TimeToSyncAfterFlashInSec        = (int)db.Configuration.Storage.TimeToSyncAfterFlash.AsTimeSpan.TotalSeconds;
            options.NumOfConcurrentSyncsPerPhysDrive = db.Configuration.Storage.NumberOfConcurrentSyncsPerPhysicalDrive;
            Sodium.CloneKey(out options.MasterKey, db.MasterKey);

            Environment = new StorageEnvironment(options);

            NotificationsStorage = new NotificationsStorage(db.Name);

            OperationsStorage = new OperationsStorage();

            ContextPool = new TransactionContextPool(Environment);
        }
Esempio n. 13
0
        public RaftNode(int port)
        {
            _name = "node-" + port;
            _url  = string.Format("http://{0}:{1}", Environment.MachineName, port);

            var nodeTransport = new HttpTransport(_name);

            var node1 = new NodeConnectionInfo {
                Name = _name, Uri = new Uri(_url)
            };
            var engineOptions = new RaftEngineOptions(
                node1,
                StorageEnvironmentOptions.CreateMemoryOnly(),
                nodeTransport,
                new DictionaryStateMachine());

            engineOptions.ElectionTimeout  *= 2;
            engineOptions.HeartbeatTimeout *= 2;

            _raftEngine = new RaftEngine(engineOptions);

            _server = WebApp.Start(new StartOptions
            {
                Urls = { string.Format("http://+:{0}/", port) }
            }, builder =>
            {
                var httpConfiguration = new HttpConfiguration();
                RaftWebApiConfig.Load();
                httpConfiguration.MapHttpAttributeRoutes();
                httpConfiguration.Properties[typeof(HttpTransportBus)] = nodeTransport.Bus;
                builder.UseWebApi(httpConfiguration);
            });
        }
Esempio n. 14
0
        public void PageSplitterShouldCalculateSeparatorKeyCorrectly2()
        {
            var ids = ReadIds("data2.txt");

            StorageEnvironmentOptions storageEnvironmentOptions = StorageEnvironmentOptions.CreateMemoryOnly();

            storageEnvironmentOptions.MaxScratchBufferSize *= 2;
            using (var env = new StorageEnvironment(storageEnvironmentOptions))
            {
                var rand       = new Random();
                var testBuffer = new byte[69];
                rand.NextBytes(testBuffer);

                var trees = CreateTrees(env, 1, "tree");

                foreach (var id in ids)
                {
                    using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
                    {
                        foreach (var treeName in trees)
                        {
                            var tree = tx.Environment.State.GetTree(tx, treeName);
                            tree.Add(id, new MemoryStream(testBuffer));
                        }

                        tx.Commit();
                    }
                }

                ValidateRecords(env, trees, ids);
            }
        }
Esempio n. 15
0
        public void IterationShouldNotFindAnyRecordsAndShouldNotThrowWhenNumberOfEntriesOnPageIs1AndKeyDoesNotMatch()
        {
            using (var env = new StorageEnvironment(StorageEnvironmentOptions.CreateMemoryOnly()))
            {
                using (var tx = env.WriteTransaction())
                {
                    tx.CreateTree("tree");

                    tx.Commit();
                }

                using (var tx = env.WriteTransaction())
                {
                    var tree = tx.ReadTree("tree");
                    tree.Add(@"Raven\Database\1", StreamFor("123"));

                    tx.Commit();
                }

                using (var snapshot = env.ReadTransaction())
                    using (var iterator = snapshot.ReadTree("tree").Iterate(false))
                    {
                        Slice v;
                        Slice.From(snapshot.Allocator, @"Raven\Filesystem\", out v);
                        Assert.False(iterator.Seek(v));
                    }
            }
        }
Esempio n. 16
0
        public void DataIsKeptAfterRestart()
        {
            using (var pureMemoryPager = StorageEnvironmentOptions.CreateMemoryOnly())
            {
                pureMemoryPager.OwnsPagers = false;
                using (var env = new StorageEnvironment(pureMemoryPager))
                {
                    using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
                    {
                        tx.State.Root.Add("test/1", new MemoryStream());
                        tx.Commit();
                    }
                    using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
                    {
                        tx.State.Root.Add("test/2", new MemoryStream());
                        tx.Commit();
                    }
                }

                using (var env = new StorageEnvironment(pureMemoryPager))
                {
                    using (var tx = env.NewTransaction(TransactionFlags.Read))
                    {
                        Assert.NotNull(tx.State.Root.Read("test/1"));
                        Assert.NotNull(tx.State.Root.Read("test/2"));
                        tx.Commit();
                    }
                }
            }
        }
Esempio n. 17
0
        public void DataIsKeptAfterRestart()
        {
            using (var pureMemoryPager = StorageEnvironmentOptions.CreateMemoryOnly())
            {
                pureMemoryPager.OwnsPagers = false;
                using (var env = new StorageEnvironment(pureMemoryPager))
                {
                    using (var tx = env.WriteTransaction())
                    {
                        var tree = tx.CreateTree("foo");
                        tree.Add("test/1", new MemoryStream());
                        tx.Commit();
                    }
                    using (var tx = env.WriteTransaction())
                    {
                        var tree = tx.CreateTree("foo");
                        tree.Add("test/2", new MemoryStream());
                        tx.Commit();
                    }
                }

                using (var env = new StorageEnvironment(pureMemoryPager))
                {
                    using (var tx = env.ReadTransaction())
                    {
                        var tree = tx.CreateTree("foo");
                        Assert.NotNull(tree.Read("test/1"));
                        Assert.NotNull(tree.Read("test/2"));
                        tx.Commit();
                    }
                }
            }
        }
Esempio n. 18
0
        public HttpTransportPingTest()
        {
            _node1Transport = new HttpTransport("node1", _requestsTimeout, CancellationToken.None);

            var node1 = new NodeConnectionInfo {
                Name = "node1", Uri = new Uri("http://localhost:9079")
            };
            var engineOptions = new RaftEngineOptions(node1, StorageEnvironmentOptions.CreateMemoryOnly(), _node1Transport, new DictionaryStateMachine())
            {
                ElectionTimeout  = 60 * 1000,
                HeartbeatTimeout = 10 * 1000
            };

            _raftEngine = new RaftEngine(engineOptions);

            NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(9079);

            _server = WebApp.Start(new StartOptions
            {
                Urls = { "http://+:9079/" }
            }, builder =>
            {
                var httpConfiguration = new HttpConfiguration();
                RaftWebApiConfig.Load();
                httpConfiguration.MapHttpAttributeRoutes();
                httpConfiguration.Properties[typeof(HttpTransportBus)] = _node1Transport.Bus;
                builder.UseWebApi(httpConfiguration);
            });
        }
Esempio n. 19
0
        public void StorageEnvironment_should_be_able_to_accept_transactionsToShip_with_LOTS_of_transactions()
        {
            var transactionsToShip = new ConcurrentBag <TransactionToShip>();

            Env.Journal.OnTransactionCommit += transactionsToShip.Add;

            using (var tx = Env.NewTransaction(TransactionFlags.ReadWrite))
            {
                Env.CreateTree(tx, "TestTree");
                Env.CreateTree(tx, "TestTree2");
                tx.Commit();
            }

            WriteLotsOfTestDataForTree("TestTree");
            WriteLotsOfTestDataForTree("TestTree2");

            using (var shippingDestinationEnv = new StorageEnvironment(StorageEnvironmentOptions.CreateMemoryOnly()))
            {
                Assert.DoesNotThrow(() => shippingDestinationEnv.Journal.Shipper.ApplyShippedLogs(transactionsToShip));

                using (var snapshot = shippingDestinationEnv.CreateSnapshot())
                {
                    ValidateLotsOfTestDataForTree(snapshot, "TestTree");
                    ValidateLotsOfTestDataForTree(snapshot, "TestTree2");
                }
            }
        }
Esempio n. 20
0
        public void ShouldWork()
        {
            using (var env = new StorageEnvironment(StorageEnvironmentOptions.CreateMemoryOnly()))
            {
                using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
                {
                    var s    = new string('0', 500);
                    var tree = env.CreateTree(tx, "data");
                    for (int i = 0; i < 10; i++)
                    {
                        tree.Add("users-" + i + "-" + s, new byte[0]);
                    }
                    tx.Commit();
                }

                using (var tx = env.NewTransaction(TransactionFlags.Read))
                {
                    var tree = tx.ReadTree("data");
                    using (var it = tree.Iterate())
                    {
                        Assert.True(it.Seek("users-7"));

                        for (int i = 0; i < 10; i++)
                        {
                            Assert.True(it.Seek("users-" + i), i.ToString());
                        }
                    }
                }
            }
        }
Esempio n. 21
0
        public void StorageEnvironment_should_be_able_to_accept_transactionsToShip_with_new_trees_no_flushing()
        {
            var transactionsToShip = new ConcurrentBag <TransactionToShip>();

            using (var shippingSourceEnv = new StorageEnvironment(StorageEnvironmentOptions.CreateMemoryOnly()))
            {
                shippingSourceEnv.Journal.OnTransactionCommit += tx =>
                {
                    tx.CreatePagesSnapshot();
                    transactionsToShip.Add(tx);
                };

                using (var tx = shippingSourceEnv.NewTransaction(TransactionFlags.ReadWrite))
                {
                    shippingSourceEnv.CreateTree(tx, "TestTree");
                    tx.Commit();
                }
            }

            var storageEnvironmentOptions = StorageEnvironmentOptions.CreateMemoryOnly();

            storageEnvironmentOptions.ManualFlushing = true;
            using (var shippingDestinationEnv = new StorageEnvironment(storageEnvironmentOptions))
            {
                foreach (var tx in transactionsToShip)
                {
                    shippingDestinationEnv.Journal.Shipper.ApplyShippedLog(tx.PagesSnapshot);
                }

                using (var snapshot = shippingDestinationEnv.CreateSnapshot())
                {
                    snapshot.Read("TestTree", "Foo");
                }
            }
        }
Esempio n. 22
0
        public void Initialize(UuidGenerator generator, OrderedPartCollection <AbstractFileCodec> codecs)
        {
            if (codecs == null)
            {
                throw new ArgumentNullException("codecs");
            }

            fileCodecs    = codecs;
            uuidGenerator = generator;

            bool runInMemory;

            bool.TryParse(settings[Constants.RunInMemory], out runInMemory);

            var persistenceSource = runInMemory ? StorageEnvironmentOptions.CreateMemoryOnly() :
                                    CreateStorageOptionsFromConfiguration(path, settings);

            tableStorage = new TableStorage(persistenceSource, bufferPool);
            var schemaCreator = new SchemaCreator(configuration, tableStorage, Output, Log);

            schemaCreator.CreateSchema();
            schemaCreator.SetupDatabaseIdAndSchemaVersion();
            schemaCreator.UpdateSchemaIfNecessary();

            SetupDatabaseId();
            idGenerator = new IdGenerator(tableStorage);
        }
Esempio n. 23
0
        public void CanCleanExpiredMetrics()
        {
            var files = new List <string>(new[] { "file1.txt", "file2.txt", "file3.txt" });

            using (var env = new StorageEnvironment(StorageEnvironmentOptions.CreateMemoryOnly()))
            {
                var envWithType = new StorageEnvironmentWithType("test", StorageEnvironmentWithType.StorageEnvironmentType.Documents, env);

                foreach (var fileName in files)
                {
                    for (var i = 0; i < 2 * 256; i++)
                    {
                        var now                 = DateTime.UtcNow.AddHours(-7);
                        var meterIoRate         = env.Options.IoMetrics.MeterIoRate(fileName, IoMetrics.MeterType.JournalWrite, i + 1);
                        var durationMeasurement = new IoMeterBuffer.DurationMeasurement(meterIoRate.Parent, IoMetrics.MeterType.JournalWrite, i + 1, 0, null)
                        {
                            Start = now,
                            End   = now.AddMilliseconds(2)
                        };
                        meterIoRate.Parent.Mark(ref durationMeasurement);
                    }
                }

                CheckMetricFiles(env, files, checkForNull: false);

                IEnumerable <StorageEnvironmentWithType> environments = new[] { envWithType };
                IoMetricsUtil.CleanIoMetrics(environments, DateTime.UtcNow.Ticks);

                CheckMetricFiles(env, files, checkForNull: true);
            }
        }
Esempio n. 24
0
        public void Follower_as_a_single_node_becomes_leader_automatically()
        {
            var hub = new InMemoryTransportHub();
            var storageEnvironmentOptions = StorageEnvironmentOptions.CreateMemoryOnly();

            storageEnvironmentOptions.OwnsPagers = false;

            var raftEngineOptions = new RaftEngineOptions(
                new NodeConnectionInfo {
                Name = "node1"
            },
                storageEnvironmentOptions,
                hub.CreateTransportFor("node1"),
                new DictionaryStateMachine()
                )
            {
                ElectionTimeout  = 1000,
                HeartbeatTimeout = 1000 / 6
            };

            PersistentState.ClusterBootstrap(raftEngineOptions);
            storageEnvironmentOptions.OwnsPagers = true;

            using (var raftNode = new RaftEngine(raftEngineOptions))
            {
                Assert.Equal(RaftEngineState.Leader, raftNode.State);
            }
        }
Esempio n. 25
0
        public void CanQueryAndSort()
        {
            using (var fullTextIndex = new FullTextIndex(StorageEnvironmentOptions.CreateMemoryOnly(), new DefaultAnalyzer()))
            {
                using (var indexer = fullTextIndex.CreateIndexer())
                {
                    indexer.NewIndexEntry();

                    indexer.AddField("Name", "Oren Eini");

                    indexer.AddField("Email", "*****@*****.**");

                    indexer.NewIndexEntry();

                    indexer.AddField("Name", "Arava Eini");

                    indexer.AddField("Email", "*****@*****.**");

                    indexer.Flush();
                }

                using (var searcher = fullTextIndex.CreateSearcher())
                {
                    var results = searcher.QueryTop(new TermQuery("Name", "eini"), 5, sortBy: new Sorter("Email"));

                    Assert.Equal(2, results.Results[0].DocumentId);
                    Assert.Equal(1, results.Results[1].DocumentId);
                }
            }
        }
Esempio n. 26
0
        public ConfigurationStorage(DocumentDatabase db)
        {
            var path = db.Configuration.Core.DataDirectory.Combine("Configuration");

            var options = db.Configuration.Core.RunInMemory
                ? StorageEnvironmentOptions.CreateMemoryOnly(path.FullPath, db.Configuration.Storage.TempPath?.FullPath, db.IoChanges, db.CatastrophicFailureNotification)
                : StorageEnvironmentOptions.ForPath(path.FullPath, db.Configuration.Storage.TempPath?.FullPath, null, db.IoChanges, db.CatastrophicFailureNotification);

            options.OnNonDurableFileSystemError += db.HandleNonDurableFileSystemError;
            options.OnRecoveryError             += db.HandleOnConfigurationRecoveryError;
            options.CompressTxAboveSizeInBytes   = db.Configuration.Storage.CompressTxAboveSize.GetValue(SizeUnit.Bytes);
            options.SchemaVersion                    = SchemaUpgrader.CurrentVersion.ConfigurationVersion;
            options.SchemaUpgrader                   = SchemaUpgrader.Upgrader(SchemaUpgrader.StorageType.Configuration, this, null);
            options.ForceUsing32BitsPager            = db.Configuration.Storage.ForceUsing32BitsPager;
            options.TimeToSyncAfterFlashInSec        = (int)db.Configuration.Storage.TimeToSyncAfterFlash.AsTimeSpan.TotalSeconds;
            options.NumOfConcurrentSyncsPerPhysDrive = db.Configuration.Storage.NumberOfConcurrentSyncsPerPhysicalDrive;
            options.MasterKey = db.MasterKey?.ToArray();
            options.DoNotConsiderMemoryLockFailureAsCatastrophicError = db.Configuration.Security.DoNotConsiderMemoryLockFailureAsCatastrophicError;
            if (db.Configuration.Storage.MaxScratchBufferSize.HasValue)
            {
                options.MaxScratchBufferSize = db.Configuration.Storage.MaxScratchBufferSize.Value.GetValue(SizeUnit.Bytes);
            }

            Environment = LayoutUpdater.OpenEnvironment(options);

            NotificationsStorage = new NotificationsStorage(db.Name);

            OperationsStorage = new OperationsStorage();

            ContextPool = new TransactionContextPool(Environment);
        }
        public void AllScratchPagesShouldBeReleased()
        {
            var options = StorageEnvironmentOptions.CreateMemoryOnly();

            options.ManualFlushing = true;
            using (var env = new StorageEnvironment(options))
            {
                using (var txw = env.WriteTransaction())
                {
                    txw.CreateTree("test");

                    txw.Commit();
                }

                using (var txw = env.WriteTransaction())
                {
                    var tree = txw.CreateTree("test");

                    tree.Add("key/1", new MemoryStream(new byte[100]));
                    tree.Add("key/1", new MemoryStream(new byte[200]));
                    txw.Commit();
                }

                env.FlushLogToDataFile(); // non read nor write transactions, so it should flush and release everything from scratch

                // we keep track of the pages in scratch for one additional transaction, to avoid race
                // condition with FlushLogToDataFile concurrently with new read transactions
                Assert.Equal(2, env.ScratchBufferPool.GetNumberOfAllocations(0));
            }
        }
Esempio n. 28
0
        public void StorageEnvironment_should_be_able_to_accept_transactionsToShip()
        {
            var transactionsToShip = new ConcurrentBag <TransactionToShip>();

            Env.Journal.OnTransactionCommit += transactionsToShip.Add;

            WriteTestDataToEnv();
            using (var shippingDestinationEnv = new StorageEnvironment(StorageEnvironmentOptions.CreateMemoryOnly()))
            {
                shippingDestinationEnv.Journal.Shipper.ApplyShippedLogs(transactionsToShip);
                using (var snapshot = shippingDestinationEnv.CreateSnapshot())
                {
                    var fooReadResult = snapshot.Read("TestTree", "foo");
                    Assert.NotNull(fooReadResult);

                    var fooValue = Encoding.UTF8.GetString(fooReadResult.Reader.AsStream().ReadData());
                    Assert.Equal("bar", fooValue);

                    var barReadResult = snapshot.Read("TestTree", "bar");
                    Assert.NotNull(barReadResult);

                    var barValue = Encoding.UTF8.GetString(barReadResult.Reader.AsStream().ReadData());
                    Assert.Equal("foo", barValue);
                }
            }
        }
Esempio n. 29
0
        protected StorageTest(ITestOutputHelper output) : base(output)
        {
            IOExtensions.DeleteDirectory(DataDir);
            Options = StorageEnvironmentOptions.CreateMemoryOnly();

            Configure(Options);
            _storageEnvironment = new Lazy <StorageEnvironment>(() => new StorageEnvironment(Options), LazyThreadSafetyMode.ExecutionAndPublication);
        }
Esempio n. 30
0
        private static StorageEnvironmentOptions CreateMemoryStorageOptionsFromConfiguration(InMemoryRavenConfiguration configuration)
        {
            var options = StorageEnvironmentOptions.CreateMemoryOnly();

            options.InitialFileSize = configuration.VoronInitialFileSize;

            return(options);
        }