Exemple #1
0
        public async Task CanExecuteMultipleIndexesAsync()
        {
            using (var store = GetDocumentStore())
            {
                await IndexCreation.CreateIndexesAsync(new List <AbstractIndexCreationTask> {
                    new TestStrIndex(), new TestIntIndex()
                }, store);

                var names = await store.Maintenance.SendAsync(new GetIndexNamesOperation(0, 3));

                Assert.Equal(2, names.Length);
                Assert.Contains("TestIntIndex", names);
                Assert.Contains("TestStrIndex", names);
            }
        }
Exemple #2
0
        /// <inheritdoc/>
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            _runner.Run();
            if (cancellationToken.IsCancellationRequested)
            {
                return;
            }

            await IndexCreation.CreateIndexesAsync(typeof(SetupDocumentStore).Assembly, _store, null, _store.Database, cancellationToken);

            var indexErrors = await GetIndexErrors(maxWaitingForStaleIndexes : 30, cancellationToken);

            if (!string.IsNullOrEmpty(indexErrors))
            {
                throw new DatabaseDisabledException(indexErrors);
            }
        }
        private async void SetupIndexes()
        {
#if NET452
            await IndexCreation.CreateIndexesAsync(typeof(DeleteEventIndex).Assembly(), _store);

            await IndexCreation.CreateIndexesAsync(typeof(DeleteSnapshotIndex).Assembly(), _store);
#else
#if NETSTANDARD1_5
            await IndexCreation.CreateIndexesAsync(typeof(DeleteEventIndex).GetTypeInfo().Assembly, _store);

            await IndexCreation.CreateIndexesAsync(typeof(DeleteSnapshotIndex).GetTypeInfo().Assembly, _store);
#else
            await IndexCreation.CreateIndexesAsync(typeof(DeleteEventIndex).Assembly, _store);

            await IndexCreation.CreateIndexesAsync(typeof(DeleteSnapshotIndex).Assembly, _store);
#endif
#endif
        }
Exemple #4
0
        public void Init()
        {
            Directory.CreateDirectory(Settings.DbPath);

            var documentStore = new EmbeddableDocumentStore
            {
                DataDirectory                   = Settings.DbPath,
                UseEmbeddedHttpServer           = true,
                EnlistInDistributedTransactions = false
            };

            NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(Settings.Port);

            documentStore.Configuration.Port     = Settings.Port;
            documentStore.Configuration.HostName = Settings.Hostname;

            documentStore.Configuration.VirtualDirectory = Settings.VirtualDirectory + "/storage";

            documentStore.Initialize();

            var sw = new Stopwatch();

            sw.Start();
            Logger.Info("Index creation started");

            IndexCreation.CreateIndexesAsync(typeof(RavenBootstrapper).Assembly, documentStore)
            .ContinueWith(c =>
            {
                sw.Stop();
                if (c.IsFaulted)
                {
                    Logger.Error("Index creation failed", c.Exception);
                }
                else
                {
                    Logger.InfoFormat("Index creation completed, total time: {0}", sw.Elapsed);
                }
            });

            Configure.Instance.Configurer.RegisterSingleton <IDocumentStore>(documentStore);
            Configure.Component <RavenUnitOfWork>(DependencyLifecycle.InstancePerUnitOfWork);
            Configure.Instance.RavenPersistenceWithStore(documentStore);
        }
Exemple #5
0
        public async Task Multiple_indexes_created_withAsync_AndWith_not_existing_analyzer_should_skip_only_the_invalid_index()
        {
            using (var store = GetDocumentStore())
            {
                try
                {
                    await IndexCreation.CreateIndexesAsync(new AbstractIndexCreationTask[] { new Index1(), new Index2(), new Index3() }, store);
                }
                catch (AggregateException e)
                {
                    Assert.Contains("Index2", e.InnerExceptions.First().Message);
                }

                var indexInfo = store.Maintenance.Send(new GetStatisticsOperation()).Indexes;
                Assert.Equal(2, indexInfo.Length);
                Assert.True(indexInfo.Any(index => index.Name.Equals("Index1")));
                Assert.True(indexInfo.Any(index => index.Name.Equals("Index3")));
            }
        }
Exemple #6
0
        public async Task CreateMultipleIndexesOnMultipleShardsAsync()
        {
            try
            {
                var indexManager = new IndexManager();
                var container    = new CompositionContainer();
                container.ComposeParts(indexManager, new Index1(), new Index2());
                await IndexCreation.CreateIndexesAsync(container, documentStore);

                foreach (var shard in documentStore.ShardStrategy.Shards.Values)
                {
                    var indexInfo = shard.DatabaseCommands.GetStatistics().Indexes;
                    Assert.True(indexInfo.Any(index => index.Name.Equals("Index1")));
                    Assert.True(indexInfo.Any(index => index.Name.Equals("Index2")));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Exemple #7
0
        public async Task Multiple_indexes_created_withAsync_AndWith_not_existing_analyzer_should_skip_only_the_invalid_index()
        {
            using (var store = NewRemoteDocumentStore())
            {
                var indexManager = new IndexManager();
                var container    = new CompositionContainer();
                container.ComposeParts(indexManager, new Index1(), new Index2(), new Index3());

                try
                {
                    await IndexCreation.CreateIndexesAsync(container, store);
                }
                catch (AggregateException e)
                {
                    Assert.Contains("Index2", e.InnerExceptions.First().Message);
                }

                var indexInfo = store.DatabaseCommands.GetStatistics().Indexes;
                Assert.Equal(3, indexInfo.Length);                 //the third is Raven/DocumentEntityByName
                Assert.True(indexInfo.Any(index => index.Name.Equals("Index1")));
                Assert.True(indexInfo.Any(index => index.Name.Equals("Index3")));
            }
        }
        private static async Task SetupIndexesAsync(IDocumentStore documentStore,
                                                    Type indexAssembly,
                                                    ILogger logger,
                                                    CancellationToken cancellationToken)
        {
            if (documentStore is null)
            {
                throw new ArgumentNullException(nameof(documentStore));
            }

            if (logger is null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            if (indexAssembly != null)
            {
                logger.LogDebug(" - Creating/Updating indexes : will look for all indexes in the assembly '{indexAssembly}' ...", indexAssembly.FullName);
                await IndexCreation.CreateIndexesAsync(indexAssembly.Assembly,
                                                       documentStore,
                                                       token : cancellationToken);
            }
        }
Exemple #9
0
        private async void SetupIndexes()
        {
            await IndexCreation.CreateIndexesAsync(typeof(DeleteEventIndex).Assembly(), _store);

            await IndexCreation.CreateIndexesAsync(typeof(DeleteSnapshotIndex).Assembly(), _store);
        }
Exemple #10
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            await IndexCreation.CreateIndexesAsync(typeof(SetupDocumentStore).Assembly, _store, null, _store.Database, stoppingToken);

            _startupTaskContext.MarkTaskAsComplete();
        }
        public Task CreateIndexes(Assembly assembly, string database)
        {
            var documentStore = RavenDocumentStore.Create(Environment, database);

            return(IndexCreation.CreateIndexesAsync(assembly, documentStore));
        }
Exemple #12
0
 public static async Task RegisterAsync(Type type, IDocumentStore documentStore)
 {
     await IndexCreation.CreateIndexesAsync(type.Assembly, documentStore);
 }
        public void Init()
        {
            Directory.CreateDirectory(Settings.DbPath);

            var documentStore = new EmbeddableDocumentStore
            {
                DataDirectory                   = Settings.DbPath,
                UseEmbeddedHttpServer           = Settings.MaintenanceMode || Settings.ExposeRavenDB,
                EnlistInDistributedTransactions = false,
            };

            var localRavenLicense = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "RavenLicense.xml");

            if (File.Exists(localRavenLicense))
            {
                Logger.InfoFormat("Loading RavenDB license found from {0}", localRavenLicense);
                documentStore.Configuration.Settings["Raven/License"] = NonLockingFileReader.ReadAllTextWithoutLocking(localRavenLicense);
            }
            else
            {
                Logger.InfoFormat("Loading Embedded RavenDB license");
                documentStore.Configuration.Settings["Raven/License"] = ReadLicense();
            }

            documentStore.Configuration.Catalog.Catalogs.Add(new AssemblyCatalog(GetType().Assembly));

            if (!Settings.MaintenanceMode)
            {
                documentStore.Configuration.Settings.Add("Raven/ActiveBundles", "CustomDocumentExpiration");
            }

            documentStore.Configuration.Port     = Settings.Port;
            documentStore.Configuration.HostName = (Settings.Hostname == "*" || Settings.Hostname == "+")
                ? "localhost"
                : Settings.Hostname;
            documentStore.Configuration.CompiledIndexCacheDirectory = Settings.DbPath;
            documentStore.Configuration.VirtualDirectory            = Settings.VirtualDirectory + "/storage";
            documentStore.Conventions.SaveEnumsAsIntegers           = true;
            documentStore.Initialize();

            Logger.Info("Index creation started");

            //Create this index synchronously as we are using it straight away
            //Should be quick as number of endpoints will always be a small number
            documentStore.ExecuteIndex(new KnownEndpointIndex());

            if (Settings.CreateIndexSync)
            {
                IndexCreation.CreateIndexes(typeof(RavenBootstrapper).Assembly, documentStore);
            }
            else
            {
                IndexCreation.CreateIndexesAsync(typeof(RavenBootstrapper).Assembly, documentStore)
                .ContinueWith(c =>
                {
                    if (c.IsFaulted)
                    {
                        Logger.Error("Index creation failed", c.Exception);
                    }
                });
            }

            PurgeKnownEndpointsWithTemporaryIdsThatAreDuplicate(documentStore);

            Configure.Instance.Configurer.RegisterSingleton <IDocumentStore>(documentStore);
            Configure.Component(builder =>
            {
#pragma warning disable 618
                var context = builder.Build <PipelineExecutor>().CurrentContext;
#pragma warning restore 618

                IDocumentSession session;

                if (context.TryGet(out session))
                {
                    return(session);
                }

                throw new InvalidOperationException("No session available");
            }, DependencyLifecycle.InstancePerCall);

            Configure.Instance.RavenDBStorageWithSelfManagedSession(documentStore, false,
                                                                    () => Configure.Instance.Builder.Build <IDocumentSession>())
            .UseRavenDBSagaStorage()
            .UseRavenDBSubscriptionStorage()
            .UseRavenDBTimeoutStorage();
        }
 public static async Task CreateIndexAsync <T>(this IDocumentStore store) where T : AbstractIndexCreationTask
 {
     await IndexCreation.CreateIndexesAsync(typeof(T).Assembly, store);
 }
 public async Task AddAllIndexes(IDocumentStore store)
 {
     await IndexCreation.CreateIndexesAsync(typeof(ReadingProgram_ByUser).Assembly, store);
 }
 /// <summary>
 ///		Creates/updates the DB indexes
 /// </summary>
 public static Task CreateUpdateIndexesAsync(this IDocumentStore store) =>
 IndexCreation.CreateIndexesAsync(typeof(SetupDocumentStore).Assembly, store, null, store.Database);