internal static bool IsRolling(IndexDeploymentMode?fromDefinition, IndexDeploymentMode fromSetting) { if (fromDefinition.HasValue == false) { return(fromSetting == IndexDeploymentMode.Rolling); } return(fromDefinition == IndexDeploymentMode.Rolling); }
public static PutAutoIndexCommand Create(AutoIndexDefinitionBaseServerSide definition, string databaseName, string raftRequestId, IndexDeploymentMode mode) { var indexType = GetAutoIndexType(definition); return(new PutAutoIndexCommand(GetAutoIndexDefinition(definition, indexType), databaseName, raftRequestId, mode, SystemTime.UtcNow)); }
public PutAutoIndexCommand(AutoIndexDefinition definition, string databaseName, string uniqueRequestId, IndexDeploymentMode mode, DateTime?createdAt = null) : base(databaseName, uniqueRequestId) { Definition = definition; CreatedAt = createdAt ?? DateTime.MinValue; DefaultStaticDeploymentMode = mode; }
public PutIndexesCommand(string databaseName, string source, DateTime createdAt, string uniqueRequestId, int revisionsToKeep, IndexDeploymentMode autoDeploymentMode, IndexDeploymentMode staticDeploymentMode) : base(databaseName, uniqueRequestId) { Source = source; CreatedAt = createdAt; RevisionsToKeep = revisionsToKeep; DefaultAutoDeploymentMode = autoDeploymentMode; DefaultStaticDeploymentMode = staticDeploymentMode; }
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); } } }
public void AddIndex(IndexDefinition definition, string source, DateTime createdAt, long raftIndex, int revisionsToKeep, IndexDeploymentMode globalDeploymentMode) { var lockMode = IndexLockMode.Unlock; IndexDefinitionCompareDifferences?differences = null; if (Indexes.TryGetValue(definition.Name, out var existingDefinition)) { if (existingDefinition.LockMode != null) { lockMode = existingDefinition.LockMode.Value; } differences = existingDefinition.Compare(definition); if (differences != IndexDefinitionCompareDifferences.All) { if (differences == IndexDefinitionCompareDifferences.LockMode && definition.LockMode == null) { return; } if (differences == IndexDefinitionCompareDifferences.None) { return; } } } if (lockMode == IndexLockMode.LockedIgnore) { return; } if (lockMode == IndexLockMode.LockedError) { throw new IndexAlreadyExistException($"Cannot edit existing index {definition.Name} with lock mode {lockMode}"); } if (definition.OutputReduceToCollection != null) { long?version = raftIndex; if (differences != null) { if (differences.Value.HasFlag(IndexDefinitionCompareDifferences.Maps) == false && differences.Value.HasFlag(IndexDefinitionCompareDifferences.Reduce) == false && differences.Value.HasFlag(IndexDefinitionCompareDifferences.Fields) == false && differences.Value.HasFlag(IndexDefinitionCompareDifferences.AdditionalSources) == false && differences.Value.HasFlag(IndexDefinitionCompareDifferences.AdditionalAssemblies) == false) { // index definition change does not affect the output documents - version need to stay the same version = existingDefinition.ReduceOutputIndex; } } definition.ReduceOutputIndex = version; } Indexes[definition.Name] = definition; List <IndexHistoryEntry> history; if (IndexesHistory == null) { IndexesHistory = new Dictionary <string, List <IndexHistoryEntry> >(); } if (IndexesHistory.TryGetValue(definition.Name, out history) == false) { history = new List <IndexHistoryEntry>(); IndexesHistory.Add(definition.Name, history); } history.Insert(0, new IndexHistoryEntry { Definition = definition, CreatedAt = createdAt, Source = source }); if (history.Count > revisionsToKeep) { history.RemoveRange(revisionsToKeep, history.Count - revisionsToKeep); } if (IsRolling(definition.DeploymentMode, globalDeploymentMode)) { definition.ClusterState ??= new ClusterState(); definition.ClusterState.LastRollingDeploymentIndex = raftIndex; if (differences == null || (differences.Value & IndexDefinition.ReIndexRequiredMask) != 0) { InitializeRollingDeployment(definition.Name, createdAt, raftIndex); definition.DeploymentMode = IndexDeploymentMode.Rolling; } } }
public PutIndexCommand(IndexDefinition definition, string databaseName, string source, DateTime createdAt, string uniqueRequestId, int revisionsToKeep, IndexDeploymentMode deploymentMode) : base(databaseName, uniqueRequestId) { Definition = definition; Definition.ClusterState ??= new ClusterState(); Source = source; CreatedAt = createdAt; RevisionsToKeep = revisionsToKeep; DefaultDeploymentMode = deploymentMode; }