Ejemplo n.º 1
0
		static async Task<SyntaxNode> GetNewRootWithAddedNamespaces(Document document, SyntaxNode relativeToNode,
			CancellationToken cancellationToken, ImmutableHashSet<string> namespaceQualifiedStrings)
		{
			var namespaceWithUsings = relativeToNode
				.GetAncestorsOrThis<NamespaceDeclarationSyntax>()
				.FirstOrDefault(ns => ns.DescendantNodes().OfType<UsingDirectiveSyntax>().Any());

			var root = await document.GetSyntaxRootAsync(cancellationToken);
			SyntaxNode newRoot;

			var usings = namespaceQualifiedStrings
				.Select(ns => UsingDirective(ParseName(ns).WithAdditionalAnnotations(Simplifier.Annotation)));

			if (namespaceWithUsings != null)
			{
				var newNamespaceDeclaration = namespaceWithUsings.WithUsings(namespaceWithUsings.Usings.AddRange(usings));
				newRoot = root.ReplaceNode(namespaceWithUsings, newNamespaceDeclaration);
			}
			else
			{
				var compilationUnit = (CompilationUnitSyntax)root;
				newRoot = compilationUnit.WithUsings(compilationUnit.Usings.AddRange(usings));
			}
			return newRoot;
		}
Ejemplo n.º 2
0
        /// <summary>
        /// Update the locally stored replication progress of remote replicas with the sequence numbers given in <paramref name="info"/>.
        /// Replication progress that is greater than the corresponding sequence number in <paramref name="info"/> is reset to that
        /// </summary>
        public Task SynchronizeReplicationProgress(ReplicationEndpointInfo info)
        {
            ImmutableHashSet <string> logNames = Endpoint.CommonLogNames(info);
            var tasks = logNames.Select(name => SynchronizeReplicationProgress(info, name));

            return(Task.WhenAll(tasks));
        }
Ejemplo n.º 3
0
        private void SetStates(
            Block <T> block,
            IReadOnlyList <ActionEvaluation <T> > actionEvaluations)
        {
            HashDigest <SHA256> blockHash  = block.Hash;
            IAccountStateDelta  lastStates = actionEvaluations.Count > 0
                ? actionEvaluations[actionEvaluations.Count - 1].OutputStates
                : null;
            ImmutableHashSet <Address> updatedAddresses =
                actionEvaluations.Select(
                    a => a.OutputStates.UpdatedAddresses
                    ).Aggregate(
                    ImmutableHashSet <Address> .Empty,
                    (a, b) => a.Union(b)
                    );
            ImmutableDictionary <Address, object> totalDelta =
                updatedAddresses.Select(
                    a => new KeyValuePair <Address, object>(
                        a,
                        lastStates?.GetState(a)
                        )
                    ).ToImmutableDictionary();

            Store.SetBlockStates(
                blockHash,
                new AddressStateMap(totalDelta)
                );

            var chainId = Id.ToString();

            Store.StoreStateReference(chainId, updatedAddresses, block);
            Store.IncreaseTxNonce(chainId, block);
        }
Ejemplo n.º 4
0
        // Cognitive Complexity 5
        public static ContentView GetContentView(string contentId, IReadOnlyCollection <string> requestedUriTypes)
        {
            ImmutableHashSet <string> subsetUriTypes = AllSupportedUriTypes.Intersect(requestedUriTypes);

            if (!subsetUriTypes.Any())
            {
                throw new Exception("message");
            }

            return(new ContentView
            {
                ResultStatus = AllSupportedUriTypes.SetEquals(subsetUriTypes) ? ResultStatusComplete : ResultStatusPartial,
                Uris = subsetUriTypes.Select(uriType =>
                {
                    if (IsViewerA(uriType))
                    {
                        return $"https://{ViewerA}/{contentId}";
                    }
                    else if (IsViewerC(uriType))
                    {
                        return $"https://{ViewerC}/{contentId}";
                    }
                    else
                    {
                        return $"https://{ViewerD}/{contentId}";
                    }
                })
            });
        }
Ejemplo n.º 5
0
        internal void SetStates(
            Block <T> block,
            IReadOnlyList <ActionEvaluation> actionEvaluations,
            bool buildStateReferences
            )
        {
            HashDigest <SHA256> blockHash  = block.Hash;
            IAccountStateDelta  lastStates = actionEvaluations.Count > 0
                ? actionEvaluations[actionEvaluations.Count - 1].OutputStates
                : null;
            ImmutableHashSet <Address> updatedAddresses =
                actionEvaluations.Select(
                    a => a.OutputStates.UpdatedAddresses
                    ).Aggregate(
                    ImmutableHashSet <Address> .Empty,
                    (a, b) => a.Union(b)
                    );
            ImmutableDictionary <Address, object> totalDelta =
                updatedAddresses.Select(
                    a => new KeyValuePair <Address, object>(
                        a,
                        lastStates?.GetState(a)
                        )
                    ).ToImmutableDictionary();

            Store.SetBlockStates(
                blockHash,
                new AddressStateMap(totalDelta)
                );

            if (buildStateReferences)
            {
                Store.StoreStateReference(Id, updatedAddresses, block.Hash, block.Index);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ClusterClient" /> class.
        /// </summary>
        /// <param name="settings">The settings used to configure the client.</param>
        /// <exception cref="ArgumentException">
        /// This exception is thrown when the settings contains no initial contacts.
        /// </exception>
        public ClusterClient(ClusterClientSettings settings)
        {
            if (settings.InitialContacts.Count == 0)
            {
                throw new ArgumentException("Initial contacts for cluster client cannot be empty");
            }

            _settings        = settings;
            _failureDetector = new DeadlineFailureDetector(_settings.AcceptableHeartbeatPause, _settings.HeartbeatInterval);

            _contactPaths = settings.InitialContacts.ToImmutableHashSet();
            _initialContactsSelections = _contactPaths.Select(Context.ActorSelection).ToArray();
            _contacts = _initialContactsSelections;

            SendGetContacts();

            _contactPathsPublished = ImmutableHashSet <ActorPath> .Empty;
            _subscribers           = ImmutableList <IActorRef> .Empty;

            _heartbeatTask = Context.System.Scheduler.ScheduleTellRepeatedlyCancelable(
                settings.HeartbeatInterval,
                settings.HeartbeatInterval,
                Self,
                HeartbeatTick.Instance,
                Self);

            _refreshContactsCancelable = null;
            ScheduleRefreshContactsTick(settings.EstablishingGetContactsInterval);
            Self.Tell(RefreshContactsTick.Instance);

            _buffer = new Queue <Tuple <object, IActorRef> >();
        }
Ejemplo n.º 7
0
 public static List <List <Unacked> > PartitionMessageId(this ImmutableHashSet <Unacked> source)
 {
     return(source
            .Select((x, i) => new { Index = i, Value = x })
            .GroupBy(x => x.Value.PartitionIndex)
            .Select(x => x.Select(v => v.Value).ToList())
            .ToList());
 }
Ejemplo n.º 8
0
        private static string GenerateGraphQLTypes(GenerationContext generationContext)
        {
            var generatableTypeProvider = new GeneratableTypeProvider(generationContext.Visitors);
            ImmutableHashSet <IGeneratableType> generatableTypes = generatableTypeProvider.FromSchemaFilePath(generationContext.GraphqlSchemaFilePath);

            IEnumerable <string> generatedTypes = generatableTypes.Select(type => type.ToString());

            return(string.Join(Environment.NewLine, generatedTypes));
        }
Ejemplo n.º 9
0
 public Scan(ImmutableHashSet <Point2d> clay)
 {
     _map = new Dictionary <Point2d, CellType>(clay.Select(p => KeyValuePair.Create(p, CellType.Clay)))
     {
         [WaterSpring] = CellType.Spring,
     };
     var(xRange, yRange) = Point2d.FindSpaceOfPoints(_map.Keys);
     _gridDimensions     = new Area2d(xRange.Pad(3), yRange);
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Returns a semi-indented JSON version of this object
        /// </summary>
        /// <returns></returns>
        public static string ToJson <T>(this ImmutableHashSet <T> hashSet, string name) where T : IAltHash
        {
            var jObj = new StringBuilder();

            jObj.AppendLine($"\"{name}\":{{");
            jObj.AppendLine(string.Join(",", hashSet.Select(r => $"\"{r.GetAltHashCode}\": {r}")));
            jObj.AppendLine("}");

            return(jObj.ToString());
        }
        public void RegisterMetrics(TelemetryClient telemetry)
        {
            foreach (var sc in _statsCollectors)
            {
                sc.RegisterMetrics(telemetry);
            }

            // Metrics have been registered, start the event listeners
            _eventListeners = _statsCollectors
                              .Select(sc => new DotNetEventListener(sc, _errorHandler))
                              .ToArray();
        }
        public void RegisterMetrics(IMetrics metrics)
        {
            // Metrics have been registered, start the event listeners
            _eventListeners = _statsCollectors
                              .Select(sc => new DotNetEventListener(sc, _errorHandler, _enabledDebugging, metrics))
                              .ToArray();

            _processInfoStatsCollector = new ProcessInfoStatsCollector(metrics);
            _processInfoStatsCollector.Start();

            SetupConstantMetrics(metrics);
        }
Ejemplo n.º 13
0
        public void A_remote_round_robin_pool_with_resizer_must_be_locally_instantiated_on_a_remote_node_after_several_resize_rounds()
        {
            Within(TimeSpan.FromSeconds(5), () =>
            {
                RunOn(() =>
                {
                    EnterBarrier("start", "broadcast-end", "end");
                }, _config.First, _config.Second, _config.Third);

                RunOn(() =>
                {
                    EnterBarrier("start");
                    var actor = Sys.ActorOf(new RoundRobinPool(
                                                nrOfInstances: 1,
                                                resizer: new TestResizer()
                                                ).Props(Props.Create <SomeActor>()), "service-hello2");
                    actor.Should().BeOfType <RoutedActorRef>();

                    actor.Tell(RouterMessage.GetRoutees);
                    // initial nrOfInstances 1 + initial resize => 2
                    ExpectMsg <Routees>().Members.Count().Should().Be(2);

                    ImmutableHashSet <IActorRef> repliesFrom = ImmutableHashSet.Create <IActorRef>();

                    for (int i = 3; i <= 9; i++)
                    {
                        //each message triggers a resize, incrementing number of routees with 1
                        actor.Tell("hit");
                        var routees = actor.AskAndWait <Routees>(new GetRoutees(), GetTimeoutOrDefault(null));
                        routees.Members.Count().Should().Be(i);
                        repliesFrom = repliesFrom.Add(ExpectMsg <IActorRef>());
                    }

                    EnterBarrier("broadcast-end");
                    actor.Tell(new Broadcast(PoisonPill.Instance));

                    EnterBarrier("end");
                    repliesFrom.Count.Should().Be(7);
                    var repliesFromAddresses = repliesFrom.Select(x => x.Path.Address).ToImmutableHashSet();
                    repliesFromAddresses.Should().BeEquivalentTo(new List <Address>
                    {
                        Node(_config.First).Address,
                        Node(_config.Second).Address,
                        Node(_config.Third).Address
                    });

                    Sys.Stop(actor);
                }, _config.Fourth);
                EnterBarrier("done");
            });
        }
Ejemplo n.º 14
0
        public static string Stringify(this object o, bool quoteStrings = false, bool nilIsEmpty = false)
        {
            if (o == null)
            {
                return(nilIsEmpty ? "" : "nil");
            }
            if (o.Equals(true))
            {
                return("true");
            }
            if (o.Equals(false))
            {
                return("false");
            }

            var s = o switch
            {
                string strng => quoteStrings ? "'" + strng + "'" : strng,
                IStringify str => str.Stringify(quoteStrings),
                ImmutableDictionary <object, object> arr => "{" + string.Join(' ', arr.Select(item => item.Key.Stringify(quoteStrings) + " " + item.Value.Stringify(quoteStrings))) + "}",
                ImmutableHashSet <object> arr => "#{" + string.Join(' ', arr.Select(item => item.Stringify(quoteStrings))) + "}",
                object[] array => "[" + string.Join(' ', array.Select(item => item.Stringify(quoteStrings))) + "]",
                ImmutableArray <object> arr => "[" + string.Join(' ', arr.Select(item => item.Stringify(quoteStrings))) + "]",
                IEnumerable <object> list => "(" + string.Join(' ', list.Select(item => item.Stringify(quoteStrings))) + ")",
                _ => o.ToString()
            };

            return(s);
        }

        // public static string Stringify(this object o)
        // {
        //  if (o == null) return "nil";
        //  if (o.Equals(true)) return "true";
        //  if (o.Equals(false)) return "false";

        //  var s = o switch
        //  {
        //      string strng => strng,
        //      IStringify str => str.Stringify(),
        //      ImmutableDictionary<object, object> arr => "{" + string.Join(' ', arr.Select(item => item.Key.Stringify() + " " + item.Value.Stringify())) + "}",
        //      ImmutableHashSet<object> arr => "#{" + string.Join(' ', arr.Select(item => item.Stringify())) + "}",
        //      object[] array => "[" + string.Join(' ', array.Select(item => item.Stringify())) + "]",
        //      ImmutableArray<object> arr => "[" + string.Join(' ', arr.Select(item => item.Stringify())) + "]",
        //      IEnumerable<object> list => "(" + string.Join(' ', list.Select(item => item.Stringify())) + ")",
        //      _ => o.ToString()
        //  };
        //  return s;
        // }
    }
Ejemplo n.º 15
0
        protected virtual HashSet <string> GetFilesToCompile(string moniker, ImmutableHashSet <string> sharedInputs)
        {
            // This is a HashSet because we allow files to be both inputs and shared inputs, and we don't want to compile the same file twice,
            // plus Roslyn needs to call Contains on this quite a lot in order to ensure its only compiling the right files so we want that to be fast.
            // When it comes to compiling the files there is no difference between shared and normal design time inputs, we just track differently because
            // shared are included in every DLL.
            var files = new HashSet <string>(sharedInputs.Count + 1, StringComparers.Paths);

            // All monikers are project relative paths by defintion (anything else is a link, and linked files can't be TempPE inputs) so we can convert
            // them to full paths using MakeRooted.
            files.AddRange(sharedInputs.Select(UnconfiguredProject.MakeRooted));
            files.Add(UnconfiguredProject.MakeRooted(moniker));
            return(files);
        }
Ejemplo n.º 16
0
        internal static async Task <ConflictResolution> RenameSymbolAsync(
            Solution solution,
            ISymbol symbol,
            string newName,
            RenameOptionSet optionSet,
            ImmutableHashSet <ISymbol> nonConflictSymbols,
            CancellationToken cancellationToken)
        {
            Contract.ThrowIfNull(solution);
            Contract.ThrowIfNull(symbol);
            Contract.ThrowIfTrue(string.IsNullOrEmpty(newName));

            cancellationToken.ThrowIfCancellationRequested();

            using (Logger.LogBlock(FunctionId.Renamer_RenameSymbolAsync, cancellationToken))
            {
                var project = solution.GetOriginatingProject(symbol);
                if (project != null)
                {
                    var client = await RemoteHostClient.TryGetClientAsync(solution.Workspace, cancellationToken).ConfigureAwait(false);

                    if (client != null)
                    {
                        var result = await client.TryRunRemoteAsync <SerializableConflictResolution>(
                            WellKnownServiceHubServices.CodeAnalysisService,
                            nameof(IRemoteRenamer.RenameSymbolAsync),
                            solution,
                            new object[]
                        {
                            SerializableSymbolAndProjectId.Create(symbol, project, cancellationToken),
                            newName,
                            SerializableRenameOptionSet.Dehydrate(optionSet),
                            nonConflictSymbols?.Select(s => SerializableSymbolAndProjectId.Dehydrate(solution, s, cancellationToken)).ToArray(),
                        },
                            callbackTarget : null,
                            cancellationToken).ConfigureAwait(false);

                        if (result.HasValue)
                        {
                            return(await result.Value.RehydrateAsync(solution, cancellationToken).ConfigureAwait(false));
                        }
                    }
                }
            }

            return(await RenameSymbolInCurrentProcessAsync(
                       solution, symbol, newName, optionSet,
                       nonConflictSymbols, cancellationToken).ConfigureAwait(false));
        }
Ejemplo n.º 17
0
        internal static void Print(ImmutableHashSet <Point3d> bugs)
        {
            var builder = new StringBuilder();
            var depths  = bugs
                          .Select(b => b.Z)
                          .Distinct()
                          .OrderBy(x => x)
                          .ToList();

            foreach (var depth in depths)
            {
                Print(builder, depth, bugs);
                builder.AppendLine();
            }

            Console.WriteLine(builder.ToString());
Ejemplo n.º 18
0
        /// <summary>
        /// Delete events from a local log identified by <paramref name="logName"/> with a sequence number less than or equal to
        /// <paramref name="toSequenceNr"/>. Deletion is split into logical deletion and physical deletion. Logical deletion is
        /// supported by any storage backend and ensures that deleted events are not replayed any more. It has
        /// immediate effect. Logically deleted events can still be replicated to remote <see cref="ReplicationEndpoint"/>s.
        /// They are only physically deleted if the storage backend supports that (currently LevelDB only). Furthermore,
        /// physical deletion only starts after all remote replication endpoints identified by <paramref name="remoteEndpointIds"/>
        /// have successfully replicated these events. Physical deletion is implemented as reliable background
        /// process that survives event log restarts.
        ///
        /// Use with care! When events are physically deleted they cannot be replicated any more to new replication
        /// endpoints (i.e. those that were unknown at the time of deletion). Also, a location with deleted events
        /// may not be suitable any more for disaster recovery of other locations.
        /// </summary>
        /// <param name="logName">Events are deleted from the local log with this name.</param>
        /// <param name="toSequenceNr">Sequence number up to which events shall be deleted (inclusive).</param>
        /// <param name="remoteEndpointIds">
        /// A set of remote <see cref="ReplicationEndpoint"/> ids that must have replicated events
        /// to their logs before they are allowed to be physically deleted at this endpoint.
        /// </param>
        /// <returns>
        /// The sequence number up to which events have been logically deleted. When the returned task
        /// completes logical deletion is effective. The returned sequence number can differ from the requested
        /// one, if:
        ///
        /// - the log's current sequence number is smaller than the requested number. In this case the current
        ///  sequence number is returned.
        /// - there was a previous successful deletion request with a higher sequence number. In this case that
        ///  number is returned.
        /// </returns>
        public async Task <long> Delete(string logName, long toSequenceNr, ImmutableHashSet <string> remoteEndpointIds)
        {
            var remoteLogIds = remoteEndpointIds
                               .Select(id => ReplicationEndpointInfo.LogId(id, logName))
                               .ToImmutableHashSet();

            var response = await Logs[logName].Ask(new Delete(toSequenceNr, remoteEndpointIds), timeout: Settings.WriteTimeout);

            switch (response)
            {
            case DeleteSuccess s: return(s.DeletedTo);

            case DeleteFailure f: throw f.Cause;

            default: throw new InvalidOperationException($"Expected either [{nameof(DeleteSuccess)}] or [{nameof(DeleteFailure)}] but got [{response.GetType().FullName}]");
            }
        }
Ejemplo n.º 19
0
        public void ObserveDecision(
            IDecision decision,
            ImmutableHashSet <UniqueAddress> nodesToDown
            )
        {
            var downMyself = nodesToDown.Contains(SelfUniqueAddress);

            var indirectlyConnectedLogMessage = decision.IsIndirectlyConnected
                ? $", indirectly connected [{string.Join(", ", Strategy.IndirectlyConnected)}]"
                : "";

            Log.Warning(
                $"SBR took decision {decision} and is downing [{string.Join(", ", nodesToDown.Select(i => i.Address))}]{(downMyself ? " including myself, " : "")}, " +
                $"[{Strategy.Unreachable.Count}] unreachable of [{Strategy.Members.Count}] members" +
                indirectlyConnectedLogMessage +
                $", full reachability status: [{Strategy.Reachability}]");
        }
Ejemplo n.º 20
0
        public void Process(ImmutableHashSet <EvalStack> set)
        {
            if (G == null)
            {
                throw new NullReferenceException("Need to init G for node " + _id);
            }

            var x = set.Except(_I);

            if (!x.IsEmpty)
            {
                _I = _I.Union(x);
                _O = _I.Select(s => G(s)).ToImmutableHashSet();
                foreach (var n in _targets)
                {
                    n.Process(_O);
                }
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        ///     Provide completions for the specified location.
        /// </summary>
        /// <param name="location">
        ///     The <see cref="SourceLocation"/> where completions are requested.
        /// </param>
        /// <param name="projectDocument">
        ///     The <see cref="ProjectDocument"/> that contains the <paramref name="location"/>.
        /// </param>
        /// <param name="cancellationToken">
        ///     A <see cref="CancellationToken"/> that can be used to cancel the operation.
        /// </param>
        /// <returns>
        ///     A <see cref="Task{TResult}"/> that resolves either a <see cref="CompletionList"/>s, or <c>null</c> if no completions are provided.
        /// </returns>
        public override async Task <CompletionList> ProvideCompletions(SourceLocation location, ProjectDocument projectDocument, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (location == null)
            {
                throw new ArgumentNullException(nameof(location));
            }

            if (projectDocument == null)
            {
                throw new ArgumentNullException(nameof(projectDocument));
            }

            List <CompletionItem> completions = new List <CompletionItem>();

            using (await projectDocument.Lock.ReaderLockAsync())
            {
                Range replaceRange = location.Position.ToEmptyRange();

                completions.AddRange(
                    WellKnownItemAttributes
                    .Select(attributeName => new CompletionItem
                {
                    Label    = attributeName,
                    Detail   = "Attribute",
                    Kind     = CompletionItemKind.Field,
                    SortText = GetItemSortText(attributeName),
                    TextEdit = new TextEdit
                    {
                        NewText = $"{attributeName}=\"$1\"$0".WithPadding(PaddingType.None),
                        Range   = replaceRange.ToLsp()
                    },
                    InsertTextFormat = InsertTextFormat.Snippet
                })
                    );
            }

            if (completions.Count == 0)
            {
                return(null);
            }

            return(new CompletionList(completions, isIncomplete: false));
        }
        public void RegisterMetrics(TCollectorRegistry registry)
        {
#if PROMV2
            var metrics = new MetricFactory(registry);
#elif PROMV3
            var metrics = Metrics.WithCustomRegistry(registry);
#endif

            foreach (var sc in _statsCollectors)
            {
                sc.RegisterMetrics(metrics);
            }

            // Metrics have been registered, start the event listeners
            _eventListeners = _statsCollectors
                              .Select(sc => new DotNetEventListener(sc, _errorHandler, _enabledDebugging))
                              .ToArray();

            SetupConstantMetrics(metrics);
        }
Ejemplo n.º 23
0
            /// <inheritdoc/>
            public override string ToString()
            {
                string FormatWatchingRefs()
                {
                    if (!_watchingRefs.Any())
                    {
                        return("");
                    }
                    return($"{string.Join(", ", _watchingRefs.Select(r => r.Item2.Path.Name + "-> " + r.Item1.Path.Name))}");
                }

                string FormatWatchingAddresses()
                {
                    if (!_watchingAddresses.Any())
                    {
                        return("");
                    }
                    return(string.Join(",", WatchingAddresses));
                }

                return($"Stats(watching={_watching}, watchingNodes={_watchingNodes}, watchingRefs=[{FormatWatchingRefs()}], watchingAddresses=[{FormatWatchingAddresses()}])");
            }
Ejemplo n.º 24
0
        private void ProcessTxIds(TxIds message)
        {
            if (!(message.Remote is BoundPeer peer))
            {
                _logger.Information(
                    $"Ignores a {nameof(TxIds)} message because it was sent by an invalid peer: " +
                    "{PeerAddress}.",
                    message.Remote?.Address.ToHex()
                    );
                return;
            }

            _logger.Debug(
                $"Received a {nameof(TxIds)} message: {{@TxIds}}.",
                message.Ids.Select(txid => txid.ToString())
                );

            IStagePolicy <T>        stagePolicy = BlockChain.StagePolicy;
            ImmutableHashSet <TxId> newTxIds    = message.Ids
                                                  .Where(id => !_demandTxIds.ContainsKey(id))
                                                  .Where(id => !stagePolicy.HasStaged(BlockChain, id, true))
                                                  .ToImmutableHashSet();

            if (!newTxIds.Any())
            {
                _logger.Debug("No unaware transactions to receive.");
                return;
            }

            _logger.Debug(
                "Unaware transactions to receive: {@TxIds}.",
                newTxIds.Select(txid => txid.ToString())
                );
            foreach (TxId txid in newTxIds)
            {
                _demandTxIds.TryAdd(txid, peer);
            }
        }
Ejemplo n.º 25
0
        internal static async Task <ConflictResolution> ResolveConflictsAsync(
            RenameLocations renameLocationSet,
            string replacementText,
            ImmutableHashSet <ISymbol> nonConflictSymbols,
            CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            using (Logger.LogBlock(FunctionId.Renamer_FindRenameLocationsAsync, cancellationToken))
            {
                var solution = renameLocationSet.Solution;
                var client   = await RemoteHostClient.TryGetClientAsync(solution.Workspace, cancellationToken).ConfigureAwait(false);

                if (client != null)
                {
                    var result = await client.TryRunRemoteAsync <SerializableConflictResolution>(
                        WellKnownServiceHubServices.CodeAnalysisService,
                        nameof(IRemoteRenamer.ResolveConflictsAsync),
                        solution,
                        new object[]
                    {
                        renameLocationSet.Dehydrate(solution, cancellationToken),
                        replacementText,
                        nonConflictSymbols?.Select(s => SerializableSymbolAndProjectId.Dehydrate(solution, s, cancellationToken)).ToArray(),
                    },
                        callbackTarget : null,
                        cancellationToken).ConfigureAwait(false);

                    if (result.HasValue)
                    {
                        return(await result.Value.RehydrateAsync(solution, cancellationToken).ConfigureAwait(false));
                    }
                }
            }

            return(await ResolveConflictsInCurrentProcessAsync(
                       renameLocationSet, replacementText, nonConflictSymbols, cancellationToken).ConfigureAwait(false));
        }
Ejemplo n.º 26
0
            public override string ToString()
            {
                Func <string> formatWatchingRefs = () =>
                {
                    if (!_watchingRefs.Any())
                    {
                        return("");
                    }
                    return
                        ($"{_watchingRefs.Select(r => r.Item2.Path.Name + "-> " + r.Item1.Path.Name).Aggregate((a, b) => a + ", " + b)}");
                };

                Func <string> formatWatchingAddresses = () =>
                {
                    if (!_watchingAddresses.Any())
                    {
                        return("");
                    }
                    return(string.Join(",", WatchingAddresses));
                };

                return($"Stats(watching={_watching}, watchingNodes={_watchingNodes}, watchingRefs=[{formatWatchingRefs()}], watchingAddresses=[{formatWatchingAddresses()}])");
            }
Ejemplo n.º 27
0
        private void EvaluateActions(Block <T> block)
        {
            HashDigest <SHA256>?prevHash = block.PreviousHash;

            IAccountStateDelta[] deltas = block.EvaluateActions(address =>
            {
                IImmutableDictionary <Address, object> result =
                    GetStates(new[] { address }, prevHash);
                try
                {
                    return(result[address]);
                }
                catch (KeyNotFoundException)
                {
                    return(null);
                }
            }).ToArray();
            IAccountStateDelta lastStates = deltas.LastOrDefault();

            ImmutableHashSet <Address> updatedAddresses =
                deltas.Select(d => d.UpdatedAddresses).Aggregate(
                    ImmutableHashSet <Address> .Empty,
                    (a, b) => a.Union(b)
                    );
            IImmutableDictionary <Address, object> totalDelta =
                updatedAddresses.Select(
                    a => new KeyValuePair <Address, object>(
                        a,
                        lastStates?.GetState(a)
                        )
                    ).ToImmutableDictionary();

            Store.SetBlockStates(
                block.Hash,
                new AddressStateMap(totalDelta)
                );
        }
Ejemplo n.º 28
0
        private Receive Active(IActorRef receptionist)
        {
            return(message =>
            {
                if (message is Send)
                {
                    var send = (Send)message;
                    receptionist.Forward(new PublishSubscribe.Send(send.Path, send.Message, send.LocalAffinity));
                }
                else if (message is SendToAll)
                {
                    var sendToAll = (SendToAll)message;
                    receptionist.Forward(new PublishSubscribe.SendToAll(sendToAll.Path, sendToAll.Message));
                }
                else if (message is Publish)
                {
                    var publish = (Publish)message;
                    receptionist.Forward(new PublishSubscribe.Publish(publish.Topic, publish.Message));
                }
                else if (message is HeartbeatTick)
                {
                    if (!_failureDetector.IsAvailable)
                    {
                        _log.Info("Lost contact with [{0}], reestablishing connection", receptionist);
                        SendGetContacts();
                        ScheduleRefreshContactsTick(_settings.EstablishingGetContactsInterval);
                        Context.Become(Establishing);
                        _failureDetector.HeartBeat();
                    }
                    else
                    {
                        receptionist.Tell(ClusterReceptionist.Heartbeat.Instance);
                    }
                }
                else if (message is ClusterReceptionist.HeartbeatRsp)
                {
                    _failureDetector.HeartBeat();
                }
                else if (message is RefreshContactsTick)
                {
                    receptionist.Tell(ClusterReceptionist.GetContacts.Instance);
                }
                else if (message is ClusterReceptionist.Contacts)
                {
                    var contacts = (ClusterReceptionist.Contacts)message;

                    // refresh of contacts
                    if (contacts.ContactPoints.Count > 0)
                    {
                        _contactPaths = contacts.ContactPoints.Select(ActorPath.Parse).ToImmutableHashSet();
                        _contacts = _contactPaths.Select(Context.ActorSelection).ToArray();
                    }
                    PublishContactPoints();
                }
                else if (message is ActorIdentity)
                {
                    // ok, from previous establish, already handled
                }
                else
                {
                    return ContactPointMessages(message);
                }

                return true;
            });
        }
Ejemplo n.º 29
0
        private bool Establishing(object message)
        {
            ICancelable connectTimerCancelable = null;

            if (_settings.ReconnectTimeout.HasValue)
            {
                connectTimerCancelable = Context.System.Scheduler.ScheduleTellOnceCancelable(
                    _settings.ReconnectTimeout.Value,
                    Self,
                    ReconnectTimeout.Instance,
                    Self);
            }

            if (message is ClusterReceptionist.Contacts)
            {
                var contacts = (ClusterReceptionist.Contacts)message;

                if (contacts.ContactPoints.Count > 0)
                {
                    _contactPaths = contacts.ContactPoints.Select(ActorPath.Parse).ToImmutableHashSet();
                    _contacts     = _contactPaths.Select(Context.ActorSelection).ToArray();
                    _contacts.ForEach(c => c.Tell(new Identify(null)));
                }

                PublishContactPoints();
            }
            else if (message is ActorIdentity)
            {
                var actorIdentify = (ActorIdentity)message;
                var receptionist  = actorIdentify.Subject;

                if (receptionist != null)
                {
                    _log.Info("Connected to [{0}]", receptionist.Path);
                    ScheduleRefreshContactsTick(_settings.RefreshContactsInterval);
                    SendBuffered(receptionist);
                    Context.Become(Active(receptionist));
                    connectTimerCancelable?.Cancel();
                    _failureDetector.HeartBeat();
                }
                else
                {
                    // ok, use another instead
                }
            }
            else if (message is HeartbeatTick)
            {
                _failureDetector.HeartBeat();
            }
            else if (message is RefreshContactsTick)
            {
                SendGetContacts();
            }
            else if (message is Send)
            {
                var send = (Send)message;
                Buffer(new PublishSubscribe.Send(send.Path, send.Message, send.LocalAffinity));
            }
            else if (message is SendToAll)
            {
                var sendToAll = (SendToAll)message;
                Buffer(new PublishSubscribe.SendToAll(sendToAll.Path, sendToAll.Message));
            }
            else if (message is Publish)
            {
                var publish = (Publish)message;
                Buffer(new PublishSubscribe.Publish(publish.Topic, publish.Message));
            }
            else if (message is ReconnectTimeout)
            {
                _log.Warning("Receptionist reconnect not successful within {0} stopping cluster client", _settings.ReconnectTimeout);
                Context.Stop(Self);
            }
            else
            {
                return(ContactPointMessages(message));
            }

            return(true);
        }
Ejemplo n.º 30
0
        public ClusterClient(ClusterClientSettings settings)
        {
            if (settings.InitialContacts.Count == 0)
            {
                throw new ArgumentException("Initial contacts for cluster client cannot be empty");
            }

            _settings = settings;
            _failureDetector = new DeadlineFailureDetector(_settings.AcceptableHeartbeatPause, _settings.HeartbeatInterval);

            _contactPaths = settings.InitialContacts.ToImmutableHashSet();
            _initialContactsSelections = _contactPaths.Select(Context.ActorSelection).ToArray();
            _contacts = _initialContactsSelections;

            SendGetContacts();

            _contactPathsPublished = ImmutableHashSet<ActorPath>.Empty;
            _subscribers = ImmutableList<IActorRef>.Empty;

            _heartbeatTask = Context.System.Scheduler.ScheduleTellRepeatedlyCancelable(
                settings.HeartbeatInterval,
                settings.HeartbeatInterval,
                Self,
                HeartbeatTick.Instance,
                Self);

            _refreshContactsCancelable = null;
            ScheduleRefreshContactsTick(settings.EstablishingGetContactsInterval);
            Self.Tell(RefreshContactsTick.Instance);

            _buffer = new Queue<Tuple<object, IActorRef>>();
        }
Ejemplo n.º 31
0
        private bool Establishing(object message)
        {
            ICancelable connectTimerCancelable = null;
            if (_settings.ReconnectTimeout.HasValue)
            {
                connectTimerCancelable = Context.System.Scheduler.ScheduleTellOnceCancelable(
                    _settings.ReconnectTimeout.Value,
                    Self,
                    ReconnectTimeout.Instance,
                    Self);
            }

            if (message is ClusterReceptionist.Contacts)
            {
                var contacts = (ClusterReceptionist.Contacts)message;

                if (contacts.ContactPoints.Count > 0)
                {
                    _contactPaths = contacts.ContactPoints.Select(ActorPath.Parse).ToImmutableHashSet();
                    _contacts = _contactPaths.Select(Context.ActorSelection).ToArray();
                    _contacts.ForEach(c => c.Tell(new Identify(null)));
                }

                PublishContactPoints();
            }
            else if (message is ActorIdentity)
            {
                var actorIdentify = (ActorIdentity)message;
                var receptionist = actorIdentify.Subject;

                if (receptionist != null)
                {
                    _log.Info("Connected to [{0}]", receptionist.Path);
                    ScheduleRefreshContactsTick(_settings.RefreshContactsInterval);
                    SendBuffered(receptionist);
                    Context.Become(Active(receptionist));
                    connectTimerCancelable?.Cancel();
                    _failureDetector.HeartBeat();
                }
                else
                {
                    // ok, use another instead
                }
            }
            else if (message is HeartbeatTick)
            {
                _failureDetector.HeartBeat();
            }
            else if (message is RefreshContactsTick)
            {
                SendGetContacts();
            }
            else if (message is Send)
            {
                var send = (Send)message;
                Buffer(new PublishSubscribe.Send(send.Path, send.Message, send.LocalAffinity));
            }
            else if (message is SendToAll)
            {
                var sendToAll = (SendToAll)message;
                Buffer(new PublishSubscribe.SendToAll(sendToAll.Path, sendToAll.Message));
            }
            else if (message is Publish)
            {
                var publish = (Publish)message;
                Buffer(new PublishSubscribe.Publish(publish.Topic, publish.Message));
            }
            else if (message is ReconnectTimeout)
            {
                _log.Warning("Receptionist reconnect not successful within {0} stopping cluster client", _settings.ReconnectTimeout);
                Context.Stop(Self);
            }
            else
            {
                return ContactPointMessages(message);
            }

            return true;
        }
Ejemplo n.º 32
0
        private Receive Active(IActorRef receptionist)
        {
            return message =>
            {
                if (message is Send)
                {
                    var send = (Send)message;
                    receptionist.Forward(new PublishSubscribe.Send(send.Path, send.Message, send.LocalAffinity));
                }
                else if (message is SendToAll)
                {
                    var sendToAll = (SendToAll)message;
                    receptionist.Forward(new PublishSubscribe.SendToAll(sendToAll.Path, sendToAll.Message));
                }
                else if (message is Publish)
                {
                    var publish = (Publish)message;
                    receptionist.Forward(new PublishSubscribe.Publish(publish.Topic, publish.Message));
                }
                else if (message is HeartbeatTick)
                {
                    if (!_failureDetector.IsAvailable)
                    {
                        _log.Info("Lost contact with [{0}], restablishing connection", receptionist);
                        SendGetContacts();
                        ScheduleRefreshContactsTick(_settings.EstablishingGetContactsInterval);
                        Context.Become(Establishing);
                        _failureDetector.HeartBeat();
                    }
                    else
                    {
                        receptionist.Tell(ClusterReceptionist.Heartbeat.Instance);
                    }
                }
                else if (message is ClusterReceptionist.HeartbeatRsp)
                {
                    _failureDetector.HeartBeat();
                }
                else if (message is RefreshContactsTick)
                {
                    receptionist.Tell(ClusterReceptionist.GetContacts.Instance);
                }
                else if (message is ClusterReceptionist.Contacts)
                {
                    var contacts = (ClusterReceptionist.Contacts)message;

                    // refresh of contacts
                    if (contacts.ContactPoints.Count > 0)
                    {
                        _contactPaths = contacts.ContactPoints.Select(ActorPath.Parse).ToImmutableHashSet();
                        _contacts = _contactPaths.Select(Context.ActorSelection).ToArray();
                    }
                    PublishContactPoints();
                }
                else if (message is ActorIdentity)
                {
                    // ok, from previous establish, already handled
                }
                else
                {
                    return ContactPointMessages(message);
                }

                return true;
            };
        }
Ejemplo n.º 33
0
 private Tuple<IEnumerable<Cell>, int> GetPointsFromClearing(ImmutableHashSet<Cell> allCells)
 {
     IEnumerable<Cell> newCells = allCells.ToList();
     int addPoints = 0;
     foreach (int row in allCells.Select(c => c.Y).Distinct().
                                  Where(row => CheckRowFull(allCells, row)))
     {
         int rowNumber = row;
         newCells = newCells.Where(c => c.Y != rowNumber).ToList();
         var shiftCells = newCells.Where(r => r.Y < rowNumber).Select(c => new Cell(c.X, c.Y+1)).ToList();
         newCells = newCells.Where(r => r.Y > rowNumber).Union(shiftCells);
         addPoints++;
     }
     return new Tuple<IEnumerable<Cell>, int>(newCells, addPoints);
 }
Ejemplo n.º 34
0
 public override string ToString()
 {
     return($"{DocumentId?.ToString() ?? ProjectId.ToString()}, ({InvocationReasons.ToString()}), LowPriority:{IsLowPriority}, ActiveMember:{ActiveMember != null}, Retry:{IsRetry}, ({string.Join("|", Analyzers.Select(a => a.GetType().Name))})");
 }
Ejemplo n.º 35
0
        public static void writeClustering(ImmutableHashSet <ImmutableHashSet <AST.Address> > clustering, string filename)
        {
            var mclustering = new HashSet <HashSet <AST.Address> >(clustering.Select(cl => new HashSet <AST.Address>(cl)));

            writeClustering(mclustering, filename);
        }
Ejemplo n.º 36
0
        //State transition to JOINING - new node joining.
        //Received `Join` message and replies with `Welcome` message, containing
        // current gossip state, including the new joining member.
        public void Joining(UniqueAddress node, ImmutableHashSet<string> roles)
        {
            if(node.Address.Protocol != _cluster.SelfAddress.Protocol)
            {
                _log.Warning("Member with wrong protocol tried to join, but was ignored, expected [{0}] but was [{1}]",
                    _cluster.SelfAddress.Protocol, node.Address.Protocol);
            }
            else if (node.Address.System != _cluster.SelfAddress.System)
            {
                _log.Warning(
                    "Member with wrong ActorSystem name tried to join, but was ignored, expected [{0}] but was [{1}]",
                    _cluster.SelfAddress.System, node.Address.System);
            }
            else
            {
                var localMembers = _latestGossip.Members;

                // check by address without uid to make sure that node with same host:port is not allowed
                // to join until previous node with that host:port has been removed from the cluster
                var alreadyMember = localMembers.Any(m => m.Address == node.Address);
                var isUnreachable = !_latestGossip.Overview.Reachability.IsReachable(node);

                if (alreadyMember) _log.Info("Existing member [{0}] is trying to join, ignoring", node);
                else if (isUnreachable) _log.Info("Unreachable member [{0}] is trying to join, ignoring", node);
                else
                {
                    // remove the node from the failure detector
                    _cluster.FailureDetector.Remove(node.Address);

                    // add joining node as Joining
                    // add self in case someone else joins before self has joined (Set discards duplicates)
                    var newMembers = localMembers
                            .Add(Member.Create(node, roles))
                            .Add(Member.Create(_cluster.SelfUniqueAddress, _cluster.SelfRoles));

                    var newGossip = _latestGossip.Copy(members: newMembers);

                    UpdateLatestGossip(newGossip);

                    _log.Info("Node [{0}] is JOINING, roles [{1}]", node.Address,
                        roles.Select(r => r.ToString()).Aggregate("", (a, b) => a + ", " + b));

                    if (!node.Equals(SelfUniqueAddress))
                    {
                        Sender.Tell(new InternalClusterAction.Welcome(SelfUniqueAddress, _latestGossip));
                    }

                    Publish(_latestGossip);
                }
            }
        }