public virtual async Task SideBySideExecuteAsync(IAsyncDatabaseCommands asyncDatabaseCommands, DocumentConvention documentConvention, Etag minimumEtagBeforeReplace = null, DateTime?replaceTimeUtc = null, CancellationToken token = default(CancellationToken))
        {
            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 = await asyncDatabaseCommands.GetIndexAsync(replaceIndexName, token).ConfigureAwait(false);

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

                await UpdateSideBySideIndexAsync(asyncDatabaseCommands, minimumEtagBeforeReplace, replaceTimeUtc, token, replaceIndexName, indexDefinition, documentConvention).ConfigureAwait(false);

                return;
            }

            var serverDef = await asyncDatabaseCommands.GetIndexAsync(IndexName, token).ConfigureAwait(false);

            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));
                }

                await UpdateSideBySideIndexAsync(asyncDatabaseCommands, minimumEtagBeforeReplace, replaceTimeUtc, token, replaceIndexName, indexDefinition, documentConvention).ConfigureAwait(false);
            }
            else
            {
                // since index doesn't exist yet - create it in normal mode
                await asyncDatabaseCommands.PutIndexAsync(IndexName, indexDefinition, token).ConfigureAwait(false);
                await AfterExecuteAsync(asyncDatabaseCommands, documentConvention, token).ConfigureAwait(false);
            }
        }
Exemple #2
0
        /// <summary>
        /// Executes the index creation against the specified document store.
        /// </summary>
        public virtual async Task ExecuteAsync(IAsyncDatabaseCommands asyncDatabaseCommands, DocumentConvention documentConvention, CancellationToken token = default(CancellationToken))
        {
            Conventions = documentConvention;
            var indexDefinition = CreateIndexDefinition();

#if !DNXCORE50
            if (documentConvention.PrettifyGeneratedLinqExpressions)
            {
                var serverDef = await asyncDatabaseCommands.GetIndexAsync(IndexName, token).ConfigureAwait(false);

                if (serverDef != null && CurrentOrLegacyIndexDefinitionEquals(documentConvention, serverDef, indexDefinition))
                {
                    await AfterExecuteAsync(asyncDatabaseCommands, documentConvention, token).ConfigureAwait(false);

                    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.
            await asyncDatabaseCommands.PutIndexAsync(IndexName, indexDefinition, true, token).ConfigureAwait(false);

            if (Priority != null)
            {
                await asyncDatabaseCommands.SetIndexPriorityAsync(IndexName, Priority.Value, token).ConfigureAwait(false);
            }

            await AfterExecuteAsync(asyncDatabaseCommands, documentConvention, token).ConfigureAwait(false);
        }
        /// <summary>
        /// Executes the index creation against the specified document store.
        /// </summary>
        public virtual async Task ExecuteAsync(IAsyncDatabaseCommands asyncDatabaseCommands, DocumentConvention documentConvention)
        {
            Conventions = documentConvention;
            var indexDefinition = CreateIndexDefinition();

            if (documentConvention.PrettifyGeneratedLinqExpressions)
            {
                var serverDef = await asyncDatabaseCommands.GetIndexAsync(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.
            await asyncDatabaseCommands.PutIndexAsync(IndexName, indexDefinition, true);

            await UpdateIndexInReplicationAsync(asyncDatabaseCommands, documentConvention, (client, operationMetadata) => client.DirectPutIndexAsync(IndexName, indexDefinition, true, operationMetadata));
        }
Exemple #4
0
        public virtual async Task SideBySideExecuteAsync(IAsyncDatabaseCommands asyncDatabaseCommands, DocumentConvention documentConvention, Etag minimumEtagBeforeReplace = null, DateTime?replaceTimeUtc = null, CancellationToken token = default(CancellationToken))
        {
            Conventions = documentConvention;
            var indexDefinition = CreateIndexDefinition();
            var serverDef       = await asyncDatabaseCommands.GetIndexAsync(IndexName, token).ConfigureAwait(false);

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

                var replaceIndexName = "ReplacementOf/" + IndexName;
                await asyncDatabaseCommands.PutIndexAsync(replaceIndexName, indexDefinition, token).ConfigureAwait(false);

                await asyncDatabaseCommands
                .PutAsync(Constants.IndexReplacePrefix + replaceIndexName,
                          null,
                          RavenJObject.FromObject(new IndexReplaceDocument {
                    IndexToReplace = serverDef.Name, MinimumEtagBeforeReplace = minimumEtagBeforeReplace, ReplaceTimeUtc = replaceTimeUtc
                }),
                          new RavenJObject(),
                          token).ConfigureAwait(false);
            }
            else
            {
                // since index doesn't exist yet - create it in normal mode
                await asyncDatabaseCommands.PutIndexAsync(IndexName, indexDefinition, token).ConfigureAwait(false);
            }
        }
Exemple #5
0
        /// <summary>
        /// Executes the index creation against the specified document store.
        /// </summary>
        public virtual async Task ExecuteAsync(IAsyncDatabaseCommands asyncDatabaseCommands, DocumentConvention documentConvention, CancellationToken token = default(CancellationToken))
        {
            Conventions = documentConvention;
            var indexDefinition = CreateIndexDefinition();

            if (documentConvention.PrettifyGeneratedLinqExpressions)
            {
                var serverDef = await asyncDatabaseCommands.GetIndexAsync(IndexName, token);

                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.
            await asyncDatabaseCommands.PutIndexAsync(IndexName, indexDefinition, true, token);

            if (Priority != null)
            {
                await asyncDatabaseCommands.SetIndexPriorityAsync(IndexName, Priority.Value, token);
            }

            if (Conventions.IndexAndTransformerReplicationMode.HasFlag(IndexAndTransformerReplicationMode.Indexes))
            {
                await ReplicateIndexesIfNeededAsync(asyncDatabaseCommands);
            }
        }
Exemple #6
0
        /// <summary>
        /// Executes the index creation against the specified document store.
        /// </summary>
        public virtual async Task ExecuteAsync(IAsyncDatabaseCommands asyncDatabaseCommands, DocumentConvention documentConvention, CancellationToken token = default(CancellationToken))
        {
            Conventions = documentConvention;
            var indexDefinition = CreateIndexDefinition();

            if (documentConvention.PrettifyGeneratedLinqExpressions)
            {
                var serverDef = await asyncDatabaseCommands.GetIndexAsync(IndexName, token);

                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.
            await asyncDatabaseCommands.PutIndexAsync(IndexName, indexDefinition, true, token);

            if (Conventions.IndexAndTransformerReplicationMode.HasFlag(IndexAndTransformerReplicationMode.Indexes))
            {
                await ReplicateIndexesIfNeededAsync(asyncDatabaseCommands);
            }
        }
Exemple #7
0
        public virtual async Task SideBySideExecuteAsync(IAsyncDatabaseCommands asyncDatabaseCommands, DocumentConvention documentConvention, Etag minimumEtagBeforeReplace = null, DateTime?replaceTimeUtc = null, CancellationToken token = default(CancellationToken))
        {
            Conventions = documentConvention;
            var indexDefinition = CreateIndexDefinition();

            var replaceIndexName = Constants.SideBySideIndexNamePrefix + IndexName;
            //check if side by side index exists
            var sideBySideDef = await asyncDatabaseCommands.GetIndexAsync(replaceIndexName, token).ConfigureAwait(false);

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

                await UpdateSideBySideIndexAsync(asyncDatabaseCommands, minimumEtagBeforeReplace, replaceTimeUtc, token, replaceIndexName, indexDefinition, documentConvention);

                return;
            }

            var serverDef = await asyncDatabaseCommands.GetIndexAsync(IndexName, token).ConfigureAwait(false);

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

                await UpdateSideBySideIndexAsync(asyncDatabaseCommands, minimumEtagBeforeReplace, replaceTimeUtc, token, replaceIndexName, indexDefinition, documentConvention);
            }
            else
            {
                // since index doesn't exist yet - create it in normal mode
                await asyncDatabaseCommands.PutIndexAsync(IndexName, indexDefinition, token).ConfigureAwait(false);
                await AfterExecuteAsync(asyncDatabaseCommands, documentConvention, token);
            }
        }