public RavenCommand <DatabasePutResult> GetCommand(DocumentConventions conventions, JsonOperationContext context)
 {
     return(new AddDatabaseNodeCommand(_databaseName, _node));
 }
Beispiel #2
0
 public RavenCommand GetCommand(DocumentConventions conventions, JsonOperationContext context)
 {
     throw new System.NotImplementedException();
 }
Beispiel #3
0
 public new static ClusterRequestExecutor Create(string[] urls, string databaseName, X509Certificate2 certificate, DocumentConventions conventions)
 {
     throw new NotSupportedException();
 }
Beispiel #4
0
 public RavenCommand <OperationState> GetCommand(DocumentConventions conventions, JsonOperationContext context)
 {
     return(new GetOperationStateCommand(DocumentConventions.Default, _id, _isServerStoreOperation));
 }
 public RavenCommand <ConfigureExpirationOperationResult> GetCommand(DocumentConventions conventions, JsonOperationContext ctx)
 {
     return(new ConfigureExpirationCommand(conventions, _configuration));
 }
Beispiel #6
0
        internal static SubscriptionCreationOptions CreateSubscriptionOptionsFromGeneric <T>(
            DocumentConventions conventions,
            SubscriptionCreationOptions criteria,
            Expression <Func <T, bool> > predicate,
            Expression <Func <T, object> > project,
            Action <ISubscriptionIncludeBuilder <T> > includes)
        {
            criteria ??= new SubscriptionCreationOptions();
            var collectionName = conventions.GetCollectionName(typeof(T));

            if (criteria.Query == null)
            {
                var tType            = typeof(T);
                var includeRevisions = tType.IsConstructedGenericType && tType.GetGenericTypeDefinition() == typeof(Revision <>);
                if (includeRevisions)
                {
                    collectionName = conventions.GetCollectionName(tType.GenericTypeArguments[0]);
                }
                if (includeRevisions)
                {
                    criteria.Query = $"from '{collectionName.Replace("'", "\\'")}' (Revisions = true)";
                }
                else
                {
                    criteria.Query = $"from '{collectionName.Replace("'", "\\'")}'";
                }
                criteria.Query += " as doc";
            }

            if (predicate != null)
            {
                var script = predicate.CompileToJavascript(
                    new JavascriptCompilationOptions(
                        JsCompilationFlags.BodyOnly,
                        JavascriptConversionExtensions.MathSupport.Instance,
                        new JavascriptConversionExtensions.DictionarySupport(),
                        JavascriptConversionExtensions.LinqMethodsSupport.Instance,
                        new JavascriptConversionExtensions.SubscriptionsWrappedConstantSupport(conventions),
                        new JavascriptConversionExtensions.ConstSupport(conventions),
                        new JavascriptConversionExtensions.ReplaceParameterWithNewName(predicate.Parameters[0], "this"),
                        JavascriptConversionExtensions.ToStringSupport.Instance,
                        JavascriptConversionExtensions.DateTimeSupport.Instance,
                        JavascriptConversionExtensions.InvokeSupport.Instance,
                        JavascriptConversionExtensions.NullCoalescingSupport.Instance,
                        JavascriptConversionExtensions.NestedConditionalSupport.Instance,
                        JavascriptConversionExtensions.StringSupport.Instance
                        ));

                criteria.Query = $"declare function predicate() {{ return {script} }}{Environment.NewLine}" +
                                 $"{criteria.Query}{Environment.NewLine}" +
                                 "where predicate.call(doc)";
            }

            if (project != null)
            {
                var script = project.CompileToJavascript(
                    new JavascriptCompilationOptions(
                        JsCompilationFlags.BodyOnly,
                        JavascriptConversionExtensions.MathSupport.Instance,
                        new JavascriptConversionExtensions.DictionarySupport(),
                        JavascriptConversionExtensions.LinqMethodsSupport.Instance,
                        new JavascriptConversionExtensions.ConstSupport(conventions),
                        JavascriptConversionExtensions.ToStringSupport.Instance,
                        JavascriptConversionExtensions.DateTimeSupport.Instance,
                        JavascriptConversionExtensions.InvokeSupport.Instance,
                        JavascriptConversionExtensions.NullCoalescingSupport.Instance,
                        JavascriptConversionExtensions.StringSupport.Instance,
                        JavascriptConversionExtensions.NestedConditionalSupport.Instance,
                        new JavascriptConversionExtensions.ReplaceParameterWithNewName(project.Parameters[0], "doc"),
                        JavascriptConversionExtensions.CounterSupport.Instance,
                        JavascriptConversionExtensions.CompareExchangeSupport.Instance
                        ));
                criteria.Query += Environment.NewLine + "select " + script;
            }

            if (includes != null)
            {
                var builder = new IncludeBuilder <T>(conventions);
                includes(builder);

                if (builder.DocumentsToInclude != null && builder.DocumentsToInclude.Count > 0)
                {
                    criteria.Query += Environment.NewLine + "include ";

                    var first = true;
                    foreach (var inc in builder.DocumentsToInclude)
                    {
                        var include = "doc." + inc;
                        if (first == false)
                        {
                            criteria.Query += ",";
                        }
                        first = false;

                        if (IncludesUtil.RequiresQuotes(include, out var escapedInclude))
                        {
                            criteria.Query += $"'{escapedInclude}'";
                        }
                        else
                        {
                            criteria.Query += include;
                        }
                    }
                }
            }

            return(criteria);
        }
 public RavenCommand <IndexDefinition> GetCommand(DocumentConventions conventions, JsonOperationContext context)
 {
     return(new GetIndexCommand(_indexName));
 }
 public RavenCommand<string[]> GetCommand(DocumentConventions conventions, JsonOperationContext context)
 {
     return new GetTermsCommand(_indexName, _field, _fromValue, _pageSize);
 }
Beispiel #9
0
 /// <summary>
 /// Executes the index creation against the specified document database using the specified conventions
 /// </summary>
 public virtual void Execute(IDocumentStore store, DocumentConventions conventions = null, string database = null)
 {
     AsyncHelpers.RunSync(() => ExecuteAsync(store, conventions, database));
 }
Beispiel #10
0
 public RavenCommand <ModifyOngoingTaskResult> GetCommand(DocumentConventions conventions, JsonOperationContext ctx)
 {
     return(new UpdateExternalReplication(_database, _newWatcher));
 }
        public async Task RemoveNodeWithDb()
        {
            DebuggerAttachedTimeout.DisableLongTimespan = true;
            var fromSeconds = Debugger.IsAttached ? TimeSpan.FromSeconds(15) : TimeSpan.FromSeconds(5);

            var leader = await CreateRaftClusterAndGetLeader(5);

            var db = await CreateDatabaseInCluster("MainDB", 5, leader.WebUrl);

            var watcherDb = await CreateDatabaseInCluster("WatcherDB", 1, leader.WebUrl);

            var conventions = new DocumentConventions
            {
                DisableTopologyUpdates = true
            };

            var leaderStore = new DocumentStore
            {
                Database    = "MainDB",
                Urls        = new[] { leader.WebUrl },
                Conventions = conventions
            }.Initialize();

            var watcherStore = new DocumentStore
            {
                Database    = "WatcherDB",
                Urls        = new[] { watcherDb.Item2.Single().WebUrl },
                Conventions = conventions
            }.Initialize();

            var watcher = new ExternalReplication("WatcherDB", new[] { watcherDb.Item2.Single().WebUrl });

            var watcherRes = await AddWatcherToReplicationTopology((DocumentStore)leaderStore, watcher);

            var tasks = new List <Task>();

            foreach (var ravenServer in Servers)
            {
                tasks.Add(ravenServer.ServerStore.Cluster.WaitForIndexNotification(watcherRes.RaftCommandIndex));
            }
            Assert.True(await Task.WhenAll(tasks).WaitAsync(TimeSpan.FromSeconds(5)));

            var responsibleServer = Servers.Single(s => s.ServerStore.NodeTag == watcherRes.ResponsibleNode);
            var responsibleStore  = new DocumentStore
            {
                Database    = "MainDB",
                Urls        = new[] { responsibleServer.WebUrl },
                Conventions = conventions
            }.Initialize();

            var serverNodes = db.Item2.Select(s => new ServerNode
            {
                ClusterTag = s.ServerStore.NodeTag,
                Database   = "MainDB",
                Url        = s.WebUrl
            }).ToList();

            // check that replication works.
            using (var session = leaderStore.OpenSession())
            {
                session.Store(new User
                {
                    Name = "Karmel"
                }, "users/1");
                session.SaveChanges();
            }

            Assert.True(await WaitForDocumentInClusterAsync <User>(serverNodes, "users/1", u => u.Name == "Karmel", fromSeconds));
            Assert.True(WaitForDocument <User>(watcherStore, "users/1", u => u.Name == "Karmel", 30_000));

            // remove the node from the cluster that is responsible for the external replication
            Assert.True(await leader.ServerStore.RemoveFromClusterAsync(watcherRes.ResponsibleNode).WaitAsync(fromSeconds));
            Assert.True(await responsibleServer.ServerStore.WaitForState(RachisConsensus.State.Passive).WaitAsync(fromSeconds));

            var dbInstance = await responsibleServer.ServerStore.DatabasesLandlord.TryGetOrCreateResourceStore("MainDB");

            await WaitForValueAsync(() => dbInstance.ReplicationLoader.OutgoingConnections.Count(), 0);

            // replication from the removed node should be suspended
            using (var session = responsibleStore.OpenAsyncSession())
            {
                await session.StoreAsync(new User
                {
                    Name = "Karmel2"
                }, "users/2");

                await session.SaveChangesAsync();
            }
            var nodeInCluster      = serverNodes.First(s => s.ClusterTag != responsibleServer.ServerStore.NodeTag);
            var nodeInClusterStore = new DocumentStore
            {
                Database    = "MainDB",
                Urls        = new [] { nodeInCluster.Url },
                Conventions = conventions
            }.Initialize();

            Assert.False(WaitForDocument <User>(nodeInClusterStore, "users/2", u => u.Name == "Karmel2"));
            Assert.False(WaitForDocument <User>(watcherStore, "users/2", u => u.Name == "Karmel2"));

            // the task should be reassinged within to another node
            using (var session = nodeInClusterStore.OpenSession())
            {
                session.Store(new User
                {
                    Name = "Karmel2"
                }, "users/3");
                session.SaveChanges();
            }
            Assert.True(WaitForDocument <User>(watcherStore, "users/3", u => u.Name == "Karmel2", 30_000));

            // rejoin the node
            var newLeader = Servers.Single(s => s.ServerStore.IsLeader());

            Assert.True(await newLeader.ServerStore.AddNodeToClusterAsync(responsibleServer.WebUrl, watcherRes.ResponsibleNode).WaitAsync(fromSeconds));
            Assert.True(await responsibleServer.ServerStore.WaitForState(RachisConsensus.State.Follower).WaitAsync(fromSeconds));

            using (var session = responsibleStore.OpenSession())
            {
                session.Store(new User
                {
                    Name = "Karmel4"
                }, "users/4");
                session.SaveChanges();
                Assert.True(await WaitForDocumentInClusterAsync <User>(serverNodes, "users/4", u => u.Name == "Karmel4", fromSeconds * 5));
            }

            Assert.True(WaitForDocument <User>(watcherStore, "users/4", u => u.Name == "Karmel4", 30_000));

            nodeInClusterStore.Dispose();
            leaderStore.Dispose();
            watcherStore.Dispose();
            responsibleStore.Dispose();
        }
Beispiel #12
0
 public RavenCommand<CountersDetail> GetCommand(IDocumentStore store, DocumentConventions conventions, JsonOperationContext context, HttpCache cache)
 {
     return new GetCounterValuesCommand(_docId, _counters, _returnFullResults);
 }
Beispiel #13
0
 public RavenCommand GetCommand(DocumentConventions conventions, JsonOperationContext context)
 {
     return(new SetIndexLockCommand(_indexName, _mode));
 }
 public RavenCommand <ModifyOngoingTaskResult> GetCommand(DocumentConventions conventions, JsonOperationContext ctx)
 {
     return(new ToggleTaskStateCommand(_taskId, _taskName, _type, _disable));
 }
Beispiel #15
0
 public Operation(RequestExecutor requestExecutor, Func <IDatabaseChanges> changes, DocumentConventions conventions, long id)
 {
     _requestExecutor = requestExecutor;
     _changes         = changes;
     _conventions     = conventions;
     _id = id;
 }
Beispiel #16
0
 public RavenCommand GetCommand(DocumentConventions conventions, JsonOperationContext context)
 {
     return(new PutSortersCommand(conventions, context, _sortersToAdd));
 }
Beispiel #17
0
 public RavenCommand <OperationIdResult> GetCommand(DocumentConventions conventions, JsonOperationContext ctx)
 {
     return(new RestoreBackupCommand(_restoreConfiguration, NodeTag));
 }
 public RavenCommand <CertificateRawData> GetCommand(DocumentConventions conventions, JsonOperationContext context)
 {
     return(new CreateClientCertificateCommand(_name, _permissions, _clearance, _password));
 }
 public CreateSubscriptionCommand(DocumentConventions conventions, SubscriptionCreationOptions options, string id = null)
 {
     _conventions = conventions;
     _options     = options;
     _id          = id;
 }
 public RavenCommand <ModifySolverResult> GetCommand(DocumentConventions conventions, JsonOperationContext ctx)
 {
     return(new ModifyConflictSolverCommand(conventions, _database, this));
 }
Beispiel #21
0
 public RavenCommand <List <string> > GetCommand(IDocumentStore store, DocumentConventions conventions, JsonOperationContext context, HttpCache cache)
 {
     return(new CustomQueryCommand(_rql));
 }
Beispiel #22
0
 public BatchCommand(DocumentConventions conventions, JsonOperationContext context, List <ICommandData> commands, BatchOptions options = null)
 #endregion
 {
 }
Beispiel #23
0
 public GetOperationStateCommand(DocumentConventions conventions, long id, bool isServerStoreOperation = false)
 {
     _conventions            = conventions;
     _id                     = id;
     _isServerStoreOperation = isServerStoreOperation;
 }
Beispiel #24
0
 public RavenCommand <IndexStaleness> GetCommand(DocumentConventions conventions, JsonOperationContext context)
 {
     return(new GetIndexStalenessCommand(conventions, _indexName));
 }
 public ConfigureExpirationCommand(DocumentConventions conventions, ExpirationConfiguration configuration)
 {
     _conventions   = conventions;
     _configuration = configuration;
 }
Beispiel #26
0
 public GetIndexStalenessCommand(DocumentConventions conventions, string indexName)
 {
     _conventions = conventions;
     _indexName   = indexName;
 }
 public RavenCommand <DatabasePutResult> GetCommand(DocumentConventions conventions, JsonOperationContext ctx)
 {
     return(new CreateDatabaseOperation.CreateDatabaseCommand(_databaseRecord, etag: _etag));
 }
Beispiel #28
0
 protected virtual RavenCommand <OperationState> GetOperationStateCommand(DocumentConventions conventions, long id)
 {
     return(new GetOperationStateOperation.GetOperationStateCommand(conventions, id));
 }
Beispiel #29
0
 public new static ClusterRequestExecutor CreateForSingleNodeWithoutConfigurationUpdates(string url, string databaseName, X509Certificate2 certificate,
                                                                                         DocumentConventions conventions)
 {
     throw new NotSupportedException();
 }
Beispiel #30
0
        /// <summary>
        /// Toes the index definition.
        /// </summary>
        public IndexDefinition ToIndexDefinition(DocumentConventions conventions, bool validateMap = true)
        {
            if (Map == null && validateMap)
            {
                throw new InvalidOperationException(
                          string.Format("Map is required to generate an index, you cannot create an index without a valid Map property (in index {0}).", _indexName));
            }

            try
            {
                if (Reduce != null)
                {
                    IndexDefinitionHelper.ValidateReduce(Reduce);
                }

                string querySource     = (typeof(TDocument) == typeof(object) || ContainsWhereEntityIs()) ? "docs" : IndexDefinitionHelper.GetQuerySource(conventions, typeof(TDocument));
                var    indexDefinition = new IndexDefinition
                {
                    Name     = _indexName,
                    Reduce   = IndexDefinitionHelper.PruneToFailureLinqQueryAsStringToWorkableCode <TDocument, TReduceResult>(Reduce, conventions, "results", translateIdentityProperty: false),
                    LockMode = LockMode,
                    Priority = Priority,
                    OutputReduceToCollection = OutputReduceToCollection
                };

                var indexes            = ConvertToStringDictionary(Indexes);
                var stores             = ConvertToStringDictionary(Stores);
                var analyzers          = ConvertToStringDictionary(Analyzers);
                var suggestionsOptions = ConvertToStringSet(SuggestionsOptions).ToDictionary(x => x, x => true);
                var termVectors        = ConvertToStringDictionary(TermVectors);
                var spatialOptions     = ConvertToStringDictionary(SpatialIndexes);

#pragma warning disable CS0618 // Type or member is obsolete
                if (conventions.PrettifyGeneratedLinqExpressions)
#pragma warning restore CS0618 // Type or member is obsolete
                {
                    indexDefinition.Reduce = IndexPrettyPrinter.TryFormat(indexDefinition.Reduce);
                }

                foreach (var indexesString in IndexesStrings)
                {
                    if (indexes.ContainsKey(indexesString.Key))
                    {
                        throw new InvalidOperationException("There is a duplicate key in indexes: " + indexesString.Key);
                    }
                    indexes.Add(indexesString);
                }

                foreach (var storeString in StoresStrings)
                {
                    if (stores.ContainsKey(storeString.Key))
                    {
                        throw new InvalidOperationException("There is a duplicate key in stores: " + storeString.Key);
                    }
                    stores.Add(storeString);
                }

                foreach (var analyzerString in AnalyzersStrings)
                {
                    if (analyzers.ContainsKey(analyzerString.Key))
                    {
                        throw new InvalidOperationException("There is a duplicate key in analyzers: " + analyzerString.Key);
                    }
                    analyzers.Add(analyzerString);
                }

                foreach (var termVectorString in TermVectorsStrings)
                {
                    if (termVectors.ContainsKey(termVectorString.Key))
                    {
                        throw new InvalidOperationException("There is a duplicate key in term vectors: " + termVectorString.Key);
                    }
                    termVectors.Add(termVectorString);
                }

                foreach (var spatialString in SpatialIndexesStrings)
                {
                    if (spatialOptions.ContainsKey(spatialString.Key))
                    {
                        throw new InvalidOperationException("There is a duplicate key in spatial indexes: " + spatialString.Key);
                    }
                    spatialOptions.Add(spatialString);
                }



                ApplyValues(indexDefinition, indexes, (options, value) => options.Indexing               = value);
                ApplyValues(indexDefinition, stores, (options, value) => options.Storage                 = value);
                ApplyValues(indexDefinition, analyzers, (options, value) => options.Analyzer             = value);
                ApplyValues(indexDefinition, termVectors, (options, value) => options.TermVector         = value);
                ApplyValues(indexDefinition, spatialOptions, (options, value) => options.Spatial         = value);
                ApplyValues(indexDefinition, suggestionsOptions, (options, value) => options.Suggestions = value);

                if (Map != null)
                {
                    var map = IndexDefinitionHelper.PruneToFailureLinqQueryAsStringToWorkableCode <TDocument, TReduceResult>(
                        Map,
                        conventions,
                        querySource,
                        translateIdentityProperty: true);

#pragma warning disable CS0618 // Type or member is obsolete
                    indexDefinition.Maps.Add(conventions.PrettifyGeneratedLinqExpressions ? IndexPrettyPrinter.TryFormat(map) : map);
#pragma warning restore CS0618 // Type or member is obsolete
                }

                indexDefinition.AdditionalSources = AdditionalSources;
                indexDefinition.Configuration     = Configuration;

                return(indexDefinition);
            }
            catch (Exception e)
            {
                throw new IndexCompilationException("Failed to create index " + _indexName, e);
            }
        }