Example #1
0
        /// <summary>
        /// Executes the index creation using in side-by-side mode.
        /// </summary>
        /// <param name="databaseCommands"></param>
        /// <param name="documentConvention"></param>
        public virtual void SideBySideExecute(IDatabaseCommands databaseCommands, DocumentConvention documentConvention, Etag minimumEtagBeforeReplace = null, DateTime?replaceTimeUtc = null)
        {
            Conventions = documentConvention;
            var indexDefinition = CreateIndexDefinition();
            var serverDef       = databaseCommands.GetIndex(IndexName);

            if (serverDef != null)
            {
                if (CurrentOrLegacyIndexDefinitionEquals(documentConvention, serverDef, indexDefinition))
                {
                    return;
                }

                var replaceIndexName = "ReplacementOf/" + IndexName;
                databaseCommands.PutIndex(replaceIndexName, indexDefinition);

                databaseCommands
                .Put(Constants.IndexReplacePrefix + replaceIndexName,
                     null,
                     RavenJObject.FromObject(new IndexReplaceDocument {
                    IndexToReplace = serverDef.Name, MinimumEtagBeforeReplace = minimumEtagBeforeReplace, ReplaceTimeUtc = replaceTimeUtc
                }),
                     new RavenJObject());
            }
            else
            {
                // since index doesn't exist yet - create it in normal mode
                databaseCommands.PutIndex(IndexName, indexDefinition);
            }
        }
Example #2
0
        /// <summary>
        /// Executes the index creation against the specified document database using the specified conventions
        /// </summary>
        public virtual void Execute(IDatabaseCommands databaseCommands, DocumentConvention documentConvention)
        {
            Conventions = documentConvention;
            var indexDefinition = CreateIndexDefinition();

#if !DNXCORE50
            if (documentConvention.PrettifyGeneratedLinqExpressions)
            {
                var serverDef = databaseCommands.GetIndex(IndexName);
                if (serverDef != null && CurrentOrLegacyIndexDefinitionEquals(documentConvention, serverDef, indexDefinition))
                {
                    AfterExecute(databaseCommands, documentConvention);
                    return;
                }
            }
#endif

            // This code take advantage on the fact that RavenDB will turn an index PUT
            // to a noop of the index already exists and the stored definition matches
            // the new definition.
            databaseCommands.PutIndex(IndexName, indexDefinition, true);

            if (Priority != null)
            {
                databaseCommands.SetIndexPriority(IndexName, Priority.Value);
            }

            AfterExecute(databaseCommands, documentConvention);
        }
        /// <summary>
        /// Executes the index creation against the specified document database using the specified conventions
        /// </summary>
        public virtual void Execute(IDatabaseCommands databaseCommands, DocumentConvention documentConvention)
        {
            Conventions = documentConvention;
            var indexDefinition = CreateIndexDefinition();

            if (documentConvention.PrettifyGeneratedLinqExpressions)
            {
                var serverDef = databaseCommands.GetIndex(IndexName);
                if (serverDef != null)
                {
                    if (serverDef.Equals(indexDefinition))
                    {
                        return;
                    }

                    // now we need to check if this is a legacy index...
                    var legacyIndexDefinition = GetLegacyIndexDefinition(documentConvention);
                    if (serverDef.Equals(legacyIndexDefinition))
                    {
                        return;                         // if it matches the legacy definition, do not change that (to avoid re-indexing)
                    }
                }
            }

            // This code take advantage on the fact that RavenDB will turn an index PUT
            // to a noop of the index already exists and the stored definition matches
            // the new definition.
            databaseCommands.PutIndex(IndexName, indexDefinition, true);

            UpdateIndexInReplication(databaseCommands, documentConvention, (commands, url) =>
                                     commands.DirectPutIndex(IndexName, url, true, indexDefinition));
        }
Example #4
0
        /// <summary>
        /// Executes the index creation against the specified document database using the specified conventions
        /// </summary>
        public virtual void Execute(IDatabaseCommands databaseCommands, DocumentConvention documentConvention)
        {
            Conventions = documentConvention;
            var indexDefinition = CreateIndexDefinition();

            if (documentConvention.PrettifyGeneratedLinqExpressions)
            {
                var serverDef = databaseCommands.GetIndex(IndexName);
                if (serverDef != null && CurrentOrLegacyIndexDefinitionEquals(documentConvention, serverDef, indexDefinition))
                {
                    return;
                }
            }

            // This code take advantage on the fact that RavenDB will turn an index PUT
            // to a noop of the index already exists and the stored definition matches
            // the new definition.
            databaseCommands.PutIndex(IndexName, indexDefinition, true);

            if (Priority != null)
            {
                databaseCommands.SetIndexPriority(IndexName, Priority.Value);
            }

            if (Conventions.IndexAndTransformerReplicationMode.HasFlag(IndexAndTransformerReplicationMode.Indexes))
            {
                ReplicateIndexesIfNeeded(databaseCommands);
            }
        }
        /// <summary>
        /// Executes the index creation using in side-by-side mode.
        /// </summary>
        /// <param name="databaseCommands"></param>
        /// <param name="documentConvention"></param>
        /// <param name="minimumEtagBeforeReplace">The minimum etag after which indexes will be swapped (map indexes only).</param>
        /// <param name="replaceTimeUtc">The minimum time after which indexes will be swapped.</param>
        public virtual void SideBySideExecute(IDatabaseCommands databaseCommands, DocumentConvention documentConvention, Etag minimumEtagBeforeReplace = null, DateTime?replaceTimeUtc = null)
        {
            Conventions = documentConvention;
            var indexDefinition = CreateIndexDefinition();

            if (minimumEtagBeforeReplace != null && indexDefinition.IsMapReduce)
            {
                throw new InvalidOperationException("We do not support side-by-side execution for Map-Reduce indexes when 'minimum last indexed etag' scenario is used.");
            }

            var replaceIndexName = Constants.SideBySideIndexNamePrefix + IndexName;
            //check if side by side index exists
            var sideBySideDef = databaseCommands.GetIndex(replaceIndexName);

            if (sideBySideDef != null)
            {
                if (CurrentOrLegacyIndexDefinitionEquals(documentConvention, sideBySideDef, indexDefinition))
                {
                    return;
                }

                UpdateSideBySideIndex(databaseCommands, minimumEtagBeforeReplace, replaceTimeUtc, replaceIndexName, indexDefinition, documentConvention);
                return;
            }

            //check if "regular" index exists
            var serverDef = databaseCommands.GetIndex(IndexName);

            if (serverDef != null)
            {
                if (CurrentOrLegacyIndexDefinitionEquals(documentConvention, serverDef, indexDefinition))
                {
                    return;
                }

                switch (serverDef.LockMode)
                {
                case IndexLockMode.SideBySide:
                    //keep the SideBySide lock mode from the replaced index
                    indexDefinition.LockMode = IndexLockMode.SideBySide;
                    break;

                case IndexLockMode.LockedIgnore:
                    //Nothing to do we just ignore this index
                    return;

                case IndexLockMode.LockedError:
                    throw new InvalidOperationException(string.Format("Can't replace locked index {0} its lock mode is set to: LockedError", serverDef.IndexId));
                }

                UpdateSideBySideIndex(databaseCommands, minimumEtagBeforeReplace, replaceTimeUtc, replaceIndexName, indexDefinition, documentConvention);
            }
            else
            {
                // since index doesn't exist yet - create it in normal mode
                databaseCommands.PutIndex(IndexName, indexDefinition);
                AfterExecute(databaseCommands, documentConvention);
            }
        }
        /// <summary>
        /// Executes the index creation against the specified document database using the specified conventions
        /// </summary>
        public virtual void Execute(IDatabaseCommands databaseCommands, DocumentConvention documentConvention)
        {
            Conventions = documentConvention;
            var indexDefinition = CreateIndexDefinition();

            // This code take advantage on the fact that RavenDB will turn an index PUT
            // to a noop of the index already exists and the stored definition matches
            // the new defintion.
            databaseCommands.PutIndex(IndexName, indexDefinition, true);
        }
Example #7
0
        private void UpdateSideBySideIndex(IDatabaseCommands databaseCommands, Etag minimumEtagBeforeReplace, DateTime?replaceTimeUtc, string replaceIndexName, IndexDefinition indexDefinition, DocumentConvention documentConvention)
        {
            databaseCommands.PutIndex(replaceIndexName, indexDefinition, true);

            databaseCommands
            .Put(Constants.IndexReplacePrefix + replaceIndexName,
                 null,
                 RavenJObject.FromObject(new IndexReplaceDocument {
                IndexToReplace = IndexName, MinimumEtagBeforeReplace = minimumEtagBeforeReplace, ReplaceTimeUtc = replaceTimeUtc
            }),
                 new RavenJObject());

            AfterExecute(databaseCommands, documentConvention);
        }
        /// <summary>
        /// Executes the index creation using in side-by-side mode.
        /// </summary>
        /// <param name="databaseCommands"></param>
        /// <param name="documentConvention"></param>
        /// <param name="minimumEtagBeforeReplace">The minimum etag after which indexes will be swapped.</param>
        /// <param name="replaceTimeUtc">The minimum time after which indexes will be swapped.</param>
        public virtual void SideBySideExecute(IDatabaseCommands databaseCommands, DocumentConvention documentConvention, long?minimumEtagBeforeReplace = null, DateTime?replaceTimeUtc = null)
        {
            Conventions = documentConvention;
            var indexDefinition = CreateIndexDefinition();

            var replaceIndexName = Constants.SideBySideIndexNamePrefix + IndexName;
            //check if side by side index exists
            var sideBySideDef = databaseCommands.GetIndex(replaceIndexName);

            if (sideBySideDef != null)
            {
                if (CurrentOrLegacyIndexDefinitionEquals(documentConvention, sideBySideDef, indexDefinition))
                {
                    return;
                }

                UpdateSideBySideIndex(databaseCommands, minimumEtagBeforeReplace, replaceTimeUtc, replaceIndexName, indexDefinition, documentConvention);
                return;
            }

            //check if "regular" index exists
            var serverDef = databaseCommands.GetIndex(IndexName);

            if (serverDef != null)
            {
                if (CurrentOrLegacyIndexDefinitionEquals(documentConvention, serverDef, indexDefinition))
                {
                    return;
                }

                switch (serverDef.LockMode)
                {
                //Nothing to do we just ignore this index
                case IndexLockMode.LockedIgnore:
                    return;

                case IndexLockMode.LockedError:
                    throw new InvalidOperationException(string.Format("Can't replace locked index {0} its lock mode is set to:LockedError", serverDef.IndexId));
                }

                UpdateSideBySideIndex(databaseCommands, minimumEtagBeforeReplace, replaceTimeUtc, replaceIndexName, indexDefinition, documentConvention);
            }
            else
            {
                // since index doesn't exist yet - create it in normal mode
                databaseCommands.PutIndex(IndexName, indexDefinition);
                AfterExecute(databaseCommands, documentConvention);
            }
        }
Example #9
0
        /// <summary>
        /// Executes the index creation using in side-by-side mode.
        /// </summary>
        /// <param name="databaseCommands"></param>
        /// <param name="documentConvention"></param>
        public virtual void SideBySideExecute(IDatabaseCommands databaseCommands, DocumentConvention documentConvention, Etag minimumEtagBeforeReplace = null, DateTime?replaceTimeUtc = null)
        {
            Conventions = documentConvention;
            var indexDefinition = CreateIndexDefinition();

            var replaceIndexName = Constants.SideBySideIndexNamePrefix + IndexName;
            //check if side by side index exists
            var sideBySideDef = databaseCommands.GetIndex(replaceIndexName);

            if (sideBySideDef != null)
            {
                if (CurrentOrLegacyIndexDefinitionEquals(documentConvention, sideBySideDef, indexDefinition))
                {
                    return;
                }

                UpdateSideBySideIndex(databaseCommands, minimumEtagBeforeReplace, replaceTimeUtc, replaceIndexName, indexDefinition, documentConvention);
                return;
            }

            //check if "regular" index exists
            var serverDef = databaseCommands.GetIndex(IndexName);

            if (serverDef != null)
            {
                if (CurrentOrLegacyIndexDefinitionEquals(documentConvention, serverDef, indexDefinition))
                {
                    return;
                }

                UpdateSideBySideIndex(databaseCommands, minimumEtagBeforeReplace, replaceTimeUtc, replaceIndexName, indexDefinition, documentConvention);
            }
            else
            {
                // since index doesn't exist yet - create it in normal mode
                databaseCommands.PutIndex(IndexName, indexDefinition);
                AfterExecute(databaseCommands, documentConvention);
            }
        }
Example #10
0
 public Task <string> PutIndexAsync(string name, IndexDefinition indexDef, bool overwrite)
 {
     return(new CompletedTask <string>(databaseCommands.PutIndex(name, indexDef, overwrite)));
 }