コード例 #1
0
        private static MapReduceIndex CreateIndexInstance(IndexDefinition definition)
        {
            var staticIndex = IndexCompilationCache.GetIndexInstance(definition);

            var staticMapIndexDefinition = new MapReduceIndexDefinition(definition, staticIndex.Maps.Keys.ToHashSet(), staticIndex.OutputFields,
                                                                        staticIndex.GroupByFields, staticIndex.HasDynamicFields);
            var instance = new MapReduceIndex(staticMapIndexDefinition, staticIndex);

            return(instance);
        }
コード例 #2
0
        public async Task PostIndexFields()
        {
            using (ContextPool.AllocateOperationContext(out DocumentsOperationContext context))
            {
                using (var json = await context.ReadForMemoryAsync(RequestBodyStream(), "map"))
                {
                    if (json.TryGet("Map", out string map) == false)
                    {
                        throw new ArgumentException("'Map' field is mandatory, but wasn't specified");
                    }

                    json.TryGet(nameof(IndexDefinition.AdditionalSources), out BlittableJsonReaderObject additionalSourcesJson);
                    json.TryGet(nameof(IndexDefinition.AdditionalAssemblies), out BlittableJsonReaderArray additionalAssembliesArray);

                    var indexDefinition = new IndexDefinition
                    {
                        Name = "index-fields",
                        Maps =
                        {
                            map
                        },
                        AdditionalSources    = ConvertToAdditionalSources(additionalSourcesJson),
                        AdditionalAssemblies = ConvertToAdditionalAssemblies(additionalAssembliesArray)
                    };

                    try
                    {
                        var compiledIndex = IndexCompilationCache.GetIndexInstance(indexDefinition, Database.Configuration, IndexDefinitionBaseServerSide.IndexVersion.CurrentVersion);

                        var outputFields = compiledIndex.OutputFields;

                        await using (var writer = new AsyncBlittableJsonTextWriter(context, ResponseBodyStream()))
                        {
                            writer.WriteStartObject();
                            writer.WriteArray(context, "Results", outputFields, (w, c, field) => w.WriteString(field));
                            writer.WriteEndObject();
                        }
                    }
                    catch (IndexCompilationException)
                    {
                        // swallow compilation exception and return empty array as response
                        await using (var writer = new AsyncBlittableJsonTextWriter(context, ResponseBodyStream()))
                        {
                            writer.WriteStartArray();
                            writer.WriteEndArray();
                        }
                    }
                }
            }
        }
コード例 #3
0
ファイル: IndexStore.cs プロジェクト: janmarques/ravendb
        public async Task <Index> CreateIndex(IndexDefinition definition)
        {
            if (definition == null)
            {
                throw new ArgumentNullException(nameof(definition));
            }

            ValidateIndexName(definition.Name, isStatic: true);
            definition.RemoveDefaultValues();
            ValidateAnalyzers(definition);

            var instance = IndexCompilationCache.GetIndexInstance(definition); // pre-compile it and validate

            await _indexLocker.WaitAsync(_documentDatabase.DatabaseShutdown);

            try
            {
                lock (_locker)
                {
                    if (definition.Type == IndexType.MapReduce)
                    {
                        MapReduceIndex.ValidateReduceResultsCollectionName(definition, instance, _documentDatabase);
                    }
                }

                var command = new PutIndexCommand(definition, _documentDatabase.Name);

                try
                {
                    var(etag, _) = await _serverStore.SendToLeaderAsync(command);

                    await _documentDatabase.RachisLogIndexNotifications.WaitForIndexNotification(etag);

                    return(GetIndex(definition.Name));
                }
                catch (CommandExecutionException e)
                {
                    throw e.InnerException;
                }
            }
            finally
            {
                _indexLocker.Release();
            }
        }
コード例 #4
0
 private static MapReduceIndexDefinition CreateIndexDefinition(IndexDefinition definition, RavenConfiguration configuration, long indexVersion, out AbstractStaticIndexBase staticIndex)
 {
     staticIndex = IndexCompilationCache.GetIndexInstance(definition, configuration);
     return(new MapReduceIndexDefinition(definition, staticIndex.Maps.Keys, staticIndex.OutputFields, staticIndex.GroupByFields, staticIndex.HasDynamicFields, staticIndex.CollectionsWithCompareExchangeReferences.Count > 0, indexVersion));
 }