Exemple #1
0
 public PutAutoIndexCommand(AutoIndexDefinition definition, string databaseName, string uniqueRequestId, IndexDeploymentMode mode, DateTime?createdAt = null)
     : base(databaseName, uniqueRequestId)
 {
     Definition = definition;
     CreatedAt  = createdAt ?? DateTime.MinValue;
     DefaultStaticDeploymentMode = mode;
 }
Exemple #2
0
        internal void AddIndex(AutoIndexDefinition definition, DateTime createdAt, long raftIndex, IndexDeploymentMode globalDeploymentMode)
        {
            IndexDefinitionCompareDifferences?differences = null;

            if (AutoIndexes.TryGetValue(definition.Name, out AutoIndexDefinition existingDefinition))
            {
                differences = existingDefinition.Compare(definition);

                if (differences == IndexDefinitionCompareDifferences.None)
                {
                    return;
                }

                differences &= ~IndexDefinitionCompareDifferences.Priority;
                differences &= ~IndexDefinitionCompareDifferences.State;

                if (differences != IndexDefinitionCompareDifferences.None)
                {
                    throw new NotSupportedException($"Can not update auto-index: {definition.Name} (compare result: {differences})");
                }
            }

            AutoIndexes[definition.Name] = definition;

            if (globalDeploymentMode == IndexDeploymentMode.Rolling)
            {
                if (differences == null || (differences.Value & IndexDefinition.ReIndexRequiredMask) != 0)
                {
                    InitializeRollingDeployment(definition.Name, createdAt, raftIndex);
                }
            }
        }
Exemple #3
0
        public void AddIndex(AutoIndexDefinition definition)
        {
            if (AutoIndexes.TryGetValue(definition.Name, out AutoIndexDefinition existingDefinition))
            {
                var result = existingDefinition.Compare(definition);

                if (result == IndexDefinitionCompareDifferences.None)
                {
                    return;
                }

                result &= ~IndexDefinitionCompareDifferences.Priority;
                result &= ~IndexDefinitionCompareDifferences.State;

                if (result != IndexDefinitionCompareDifferences.None)
                {
                    throw new NotSupportedException($"Can not update auto-index: {definition.Name} (compare result: {result})");
                }
            }

            AutoIndexes[definition.Name] = definition;
        }
 public PutAutoIndexCommand(AutoIndexDefinition definition, string databaseName)
     : base(databaseName)
 {
     Definition = definition;
 }
 public PutAutoIndexCommand(AutoIndexDefinition definition, string databaseName, string uniqueRequestId)
     : base(databaseName, uniqueRequestId)
 {
     Definition = definition;
 }
Exemple #6
0
        private static AutoIndexDefinitionBase CreateAutoDefinition(AutoIndexDefinition definition)
        {
            var mapFields = definition
                            .MapFields
                            .Select(x =>
            {
                var field         = AutoIndexField.Create(x.Key, x.Value);
                field.Aggregation = x.Value.Aggregation;

                Debug.Assert(x.Value.GroupByArrayBehavior == GroupByArrayBehavior.NotApplicable);

                return(field);
            })
                            .ToArray();

            if (definition.Type == IndexType.AutoMap)
            {
                var result = new AutoMapIndexDefinition(definition.Collection, mapFields);

                if (definition.LockMode.HasValue)
                {
                    result.LockMode = definition.LockMode.Value;
                }

                if (definition.Priority.HasValue)
                {
                    result.Priority = definition.Priority.Value;
                }

                return(result);
            }

            if (definition.Type == IndexType.AutoMapReduce)
            {
                var groupByFields = definition
                                    .GroupByFields
                                    .Select(x =>
                {
                    var field                  = AutoIndexField.Create(x.Key, x.Value);
                    field.Aggregation          = x.Value.Aggregation;
                    field.GroupByArrayBehavior = x.Value.GroupByArrayBehavior;

                    return(field);
                })
                                    .ToArray();

                var result = new AutoMapReduceIndexDefinition(definition.Collection, mapFields, groupByFields);
                if (definition.LockMode.HasValue)
                {
                    result.LockMode = definition.LockMode.Value;
                }

                if (definition.Priority.HasValue)
                {
                    result.Priority = definition.Priority.Value;
                }

                return(result);
            }

            throw new NotSupportedException("Cannot create auto-index from " + definition.Type);
        }
Exemple #7
0
 public void AddIndex(AutoIndexDefinition definition)
 {
     AddIndex(definition, SystemTime.UtcNow, 0, globalDeploymentMode: IndexDeploymentMode.Parallel);
 }