private void ReplicateSideBySideIndexesMultiPut(ReplicationStrategy destination, List<IndexToAdd> indexes) { var sideBySideIndexes = new SideBySideIndexes { IndexesToAdd = indexes.ToArray() }; var serializedIndexDefinitions = RavenJToken.FromObject(sideBySideIndexes); var url = string.Format("{0}/side-by-side-indexes?{1}", destination.ConnectionStringOptions.Url, GetDebugInformation()); var replicationRequest = HttpRavenRequestFactory.Create(url, "PUT", destination.ConnectionStringOptions, Replication.GetRequestBuffering(destination)); replicationRequest.Write(serializedIndexDefinitions); replicationRequest.ExecuteRequest(); }
public List<IndexInfo> PutSideBySideIndexes(SideBySideIndexes sideBySideIndexes, bool isReplication) { var createdIndexes = new List<IndexInfo>(); var prioritiesList = new List<IndexingPriority>(); try { foreach (var indexToAdd in sideBySideIndexes.IndexesToAdd) { var originalIndexName = indexToAdd.Name.Trim(); var indexName = Constants.SideBySideIndexNamePrefix + originalIndexName; var isSideBySide = true; IndexCreationOptions? creationOptions = null; //if there is no existing side by side index, we might need to update the old index if (IndexDefinitionStorage.GetIndexDefinition(indexName) == null) { var originalIndexCreationOptions = FindIndexCreationOptions(indexToAdd.Definition, ref originalIndexName); switch (originalIndexCreationOptions) { case IndexCreationOptions.Noop: continue; case IndexCreationOptions.Create: case IndexCreationOptions.UpdateWithoutUpdatingCompiledIndex: //cases in which we don't need to create a side by side index: //1) index doesn't exist => need to create a new regular index //2) there is an existing index and we need to update its definition without reindexing indexName = originalIndexName; isSideBySide = false; creationOptions = originalIndexCreationOptions; break; } //keep the SideBySide lock mode from the replaced index indexToAdd.Definition.LockMode = GetCurrentLockMode(originalIndexName) ?? indexToAdd.Definition.LockMode; } var nameToAdd = PutIndexInternal(indexName, indexToAdd.Definition, disableIndexBeforePut: true, isUpdateBySideSide: true, creationOptions: creationOptions, isReplication: isReplication); if (nameToAdd == null) continue; createdIndexes.Add(new IndexInfo { Name = indexName, OriginalName = originalIndexName, IsSideBySide = isSideBySide, MinimumEtagBeforeReplace = indexToAdd.MinimumEtagBeforeReplace ?? sideBySideIndexes.MinimumEtagBeforeReplace, ReplaceTimeUtc = indexToAdd.ReplaceTimeUtc ?? sideBySideIndexes.ReplaceTimeUtc }); prioritiesList.Add(indexToAdd.Priority); } var indexesIds = createdIndexes.Select(x => Database.IndexStorage.GetIndexInstance(x.Name).indexId).ToArray(); Database.TransactionalStorage.Batch(accessor => accessor.Indexing.SetIndexesPriority(indexesIds, prioritiesList.ToArray())); for (var i = 0; i < createdIndexes.Count; i++) { var indexName = createdIndexes[i].Name; var priority = prioritiesList[i]; var instance = Database.IndexStorage.GetIndexInstance(indexName); if (instance == null) { Log.Warn("Couldn't set index priority because index named: '{0}' doesn't exist", indexName); continue; } instance.Priority = priority; } CreateIndexReplacementDocuments(createdIndexes); return createdIndexes; } catch (Exception e) { Log.WarnException("Could not create index batch", e); foreach (var index in createdIndexes) { DeleteIndex(index.Name); if (index.IsSideBySide) Database.Documents.Delete(index.Name, null, null); } throw; } }