コード例 #1
0
        public static Index Open <TStaticIndex>(StorageEnvironment environment, DocumentDatabase documentDatabase)
            where TStaticIndex : MapReduceIndex
        {
            var definition = MapIndexDefinition.Load(environment, out var version);

            TStaticIndex instance;

            if (typeof(TStaticIndex) == typeof(MapReduceIndex))
            {
                instance = (TStaticIndex)CreateIndexInstance <MapReduceIndex>(definition, documentDatabase.Configuration, version, (staticMapIndexDefinition, staticIndex) => new MapReduceIndex(staticMapIndexDefinition, staticIndex));
            }
            else if (typeof(TStaticIndex) == typeof(MapReduceTimeSeriesIndex))
            {
                instance = (TStaticIndex)(MapReduceIndex)CreateIndexInstance <MapReduceTimeSeriesIndex>(definition, documentDatabase.Configuration, version, (staticMapIndexDefinition, staticIndex) => new MapReduceTimeSeriesIndex(staticMapIndexDefinition, staticIndex));
            }
            else if (typeof(TStaticIndex) == typeof(MapReduceCountersIndex))
            {
                instance = (TStaticIndex)(MapReduceIndex)CreateIndexInstance <MapReduceCountersIndex>(definition, documentDatabase.Configuration, version, (staticMapIndexDefinition, staticIndex) => new MapReduceCountersIndex(staticMapIndexDefinition, staticIndex));
            }
            else
            {
                throw new NotSupportedException($"Not supported index type {typeof(TStaticIndex).Name}");
            }

            instance.Initialize(environment, documentDatabase,
                                new SingleIndexConfiguration(definition.Configuration, documentDatabase.Configuration),
                                documentDatabase.Configuration.PerformanceHints);

            return(instance);
        }
コード例 #2
0
        public static Index Open(int indexId, StorageEnvironment environment, DocumentDatabase documentDatabase)
        {
            var definition = MapIndexDefinition.Load(environment);
            var instance   = CreateIndexInstance(indexId, definition);

            instance.Initialize(environment, documentDatabase, new SingleIndexConfiguration(definition.Configuration, documentDatabase.Configuration));

            return(instance);
        }
コード例 #3
0
ファイル: MapReduceIndex.cs プロジェクト: iainwlg/ravendb
        public static Index Open(StorageEnvironment environment, DocumentDatabase documentDatabase)
        {
            var definition = MapIndexDefinition.Load(environment);
            var instance = CreateIndexInstance(definition, documentDatabase.Configuration);

            instance.Initialize(environment, documentDatabase,
                new SingleIndexConfiguration(definition.Configuration, documentDatabase.Configuration),
                documentDatabase.Configuration.PerformanceHints);

            return instance;
        }
コード例 #4
0
        public async Task CanPersistPatternForOutputReduceToCollectionReferences()
        {
            using (var store = GetDocumentStore())
            {
                var indexToCreate = new Orders_ProfitByProductAndOrderedAt();
                indexToCreate.Execute(store);

                var database = await GetDatabase(store.Database);

                var index = database.IndexStore.GetIndexes().First();

                var definition = MapIndexDefinition.Load(index._environment);
                Assert.NotNull(definition.PatternForOutputReduceToCollectionReferences);
            }
        }
コード例 #5
0
        public void Can_update_lock_mode_and_priority_of_index_even_if_indexing_is_running()
        {
            using (var database = CreateDocumentDatabase())
            {
                using (var index = MapIndex.CreateNew(new IndexDefinition()
                {
                    Name = "Users_ByName",
                    Maps =
                    {
                        "from user in docs.Users select new { user.Name }"
                    },
                    Type = IndexType.Map
                }, database))
                {
                    using (index._indexStorage._contextPool.AllocateOperationContext(out TransactionOperationContext context))
                        using (context.OpenWriteTransaction()) // open write tx to simulate running indexing batch
                        {
                            var task = Task.Factory.StartNew(() =>
                            {
                                index.SetLock(IndexLockMode.LockedIgnore);
                                index.SetPriority(IndexPriority.High);
                            }, TaskCreationOptions.LongRunning);

                            Assert.True(task.Wait(TimeSpan.FromMinutes(1)));
                        }

                    index.Start(); // will persist the introduced changes

                    IndexDefinition persistedDef = null;

                    for (int i = 0; i < 10; i++)
                    {
                        persistedDef = MapIndexDefinition.Load(index._indexStorage.Environment(), out var version);

                        if (persistedDef.Priority == IndexPriority.High)
                        {
                            break;
                        }

                        Thread.Sleep(1000);
                    }

                    Assert.Equal(IndexLockMode.LockedIgnore, persistedDef.LockMode);
                    Assert.Equal(IndexPriority.High, persistedDef.Priority);
                }
            }
        }
コード例 #6
0
ファイル: RavenDB_12932.cs プロジェクト: ikvm/ravendb
        public async Task CanPersistPatternForOutputReduceToCollectionReferences()
        {
            using (var store = GetDocumentStore())
            {
                var indexToCreate = new Orders_ProfitByProductAndOrderedAt(referencesCollectionName: "CustomCollection");
                indexToCreate.Execute(store);

                var database = await GetDatabase(store.Database);

                var index = database.IndexStore.GetIndexes().First();

                var definition = MapIndexDefinition.Load(index._environment, out var version);
                Assert.NotNull(definition.PatternForOutputReduceToCollectionReferences);
                Assert.Equal(IndexDefinitionBaseServerSide.IndexVersion.CurrentVersion, version);

                Assert.Equal("CustomCollection", definition.PatternReferencesCollectionName);
            }
        }