/// <summary> /// Constructor. /// </summary> /// <param name="r">The reader to read data from.</param> internal JobEvent(IBinaryRawReader r) : base(r) { _taskName = r.ReadString(); _taskClassName = r.ReadString(); _taskSessionId = IgniteGuid.Read(r); _jobId = IgniteGuid.Read(r); _taskNode = ReadNode(r); _taskSubjectId = r.ReadGuid(); }
/// <summary> /// Constructor. /// </summary> /// <param name="r">The reader to read data from.</param> internal JobEvent(IPortableRawReader r) : base(r) { _taskName = r.ReadString(); _taskClassName = r.ReadString(); _taskSessionId = IgniteGuid.ReadPortable(r); _jobId = IgniteGuid.ReadPortable(r); _taskNode = ReadNode(r); _taskSubjectId = r.ReadGuid() ?? Guid.Empty; }
/// <summary> /// Constructor. /// </summary> /// <param name="r">The reader to read data from.</param> internal CacheRebalancingEvent(IPortableRawReader r) : base(r) { _cacheName = r.ReadString(); _partition = r.ReadInt(); _discoveryNode = ReadNode(r); _discoveryEventType = r.ReadInt(); _discoveryEventName = r.ReadString(); _discoveryTimestamp = r.ReadLong(); }
/// <summary> /// Constructor. /// </summary> /// <param name="r">The reader to read data from.</param> internal DiscoveryEvent(IPortableRawReader r) : base(r) { _eventNode = ReadNode(r); _topologyVersion = r.ReadLong(); var nodes = IgniteUtils.ReadNodes(r); _topologyNodes = nodes == null ? null : new ReadOnlyCollection<IClusterNode>(nodes); }
/** <inheritDoc /> */ public IClusterGroup ForHost(IClusterNode node) { IgniteArgumentCheck.NotNull(node, "node"); var prj = DoOutOpObject(OpForHost, writer => { writer.WriteGuid(node.Id); }); return(GetClusterGroup(prj)); }
public bool RemoveNode(IClusterNode removedNode) { if (Nodes.TryRemove(removedNode.EndPoint, out removedNode)) { _logger.LogDebug("Removing {0}", removedNode.EndPoint); removedNode.Dispose(); removedNode = null; return(true); } return(false); }
public bool RemoveNode(IClusterNode removedNode) { _logger.LogDebug("Removing node {endPoint} from {nodes}.", _redactor.SystemData(removedNode.EndPoint), Nodes); if (Nodes.Remove(removedNode.EndPoint, out removedNode)) { _logger.LogDebug("Removed node {endPoint} from {nodes}", _redactor.SystemData(removedNode.EndPoint), Nodes); removedNode.Dispose(); return(true); } return(false); }
/** <inheritDoc /> */ public IClusterGroup ForHost(IClusterNode node) { IgniteArgumentCheck.NotNull(node, "node"); IUnmanagedTarget prj = DoProjetionOutOp(OpForHost, writer => { writer.WriteGuid(node.Id); }); return(GetClusterGroup(prj)); }
public SCircleLayoutForCircles(CircleNodeScene scene, IClusterNode clusterNode) : base(scene.Graph, clusterNode) { this.mScene = scene; Box2F bbox = clusterNode.LayoutBBox; this.CenterX = bbox.X + bbox.W / 2; this.CenterY = bbox.Y + bbox.H / 2; this.AdaptToSizeChanges = true; }
/// <summary> /// Asserts that client and server node representations are equals. /// </summary> /// <param name="clusterNode"></param> /// <param name="clientNode"></param> private static void AssertNodesAreEqual(IClusterNode clusterNode, IClientClusterNode clientNode) { AssertExtensions.ReflectionEqual(clusterNode.Id, clientNode.Id); AssertExtensions.ReflectionEqual(clusterNode.Addresses, clientNode.Addresses); AssertExtensions.ReflectionEqual(clusterNode.HostNames, clientNode.HostNames); AssertExtensions.ReflectionEqual(clusterNode.IsClient, clientNode.IsClient); AssertExtensions.ReflectionEqual(clusterNode.IsDaemon, clientNode.IsDaemon); AssertExtensions.ReflectionEqual(clusterNode.IsLocal, clientNode.IsLocal); AssertExtensions.ReflectionEqual(clusterNode.Order, clientNode.Order); AssertExtensions.ReflectionEqual(clusterNode.Version, clientNode.Version); AssertExtensions.ReflectionEqual(clusterNode.Attributes, clientNode.Attributes); }
/** <inheritDoc /> */ public IDictionary <IComputeJob <int>, IClusterNode> Map(IList <IClusterNode> subgrid, string arg) { var res = new Dictionary <IComputeJob <int>, IClusterNode>(); var job = new StringLengthEmptyJob(arg); IClusterNode node = subgrid[TestUtils.Random.Next(subgrid.Count)]; res.Add(job, node); return(res); }
public virtual void OnGenerateEnd(IClusterNode root) { if (IsVerbose) { int estimatedMaxNodeCount = CalculateEstimatedNodeCount(MaxBucketCounts); int estimatedMinNodeCount = CalculateEstimatedNodeCount(MinBucketCounts); int actualNodeCount = CountNodes <int> .Count <ClusterTree, IClusterNode>(null, root); Console.WriteLine("Nodes: estimated min: {0:#,#}, estimated max: {1:#,#}, actual: {2:#,#}", estimatedMinNodeCount, estimatedMaxNodeCount, actualNodeCount); } }
/// <summary> /// Initializes a new instance of the <see cref="EventBase"/> class. /// </summary> /// <param name="r">The reader to read data from.</param> protected EventBase(IPortableRawReader r) { _id = IgniteGuid.ReadPortable(r); _localOrder = r.ReadLong(); _node = ReadNode(r); _message = r.ReadString(); _type = r.ReadInt(); _name = r.ReadString(); _timeStamp = r.ReadDate() ?? DateTime.Now; }
public void TestAffinity() { IIgnite g = Ignition.GetIgnite("grid-0"); ICacheAffinity aff = g.GetAffinity("default"); IClusterNode node = aff.MapKeyToNode(new AffinityTestKey(0, 1)); for (int i = 0; i < 10; i++) { Assert.AreEqual(node.Id, aff.MapKeyToNode(new AffinityTestKey(i, 1)).Id); } }
public KKLayoutAlgorithm(Digraph <Node, Edge> graph, IClusterNode clusterNode) : base(graph, clusterNode) { this.mShortestPathsAlg = new BasicAllShortestPaths <Node, Edge>( new DijkstraShortestPath <Node, Edge>( graph, false, false)); this.mXs = new double[0]; this.mYs = new double[0]; this.mHidden = new bool[0]; this.MaxIterations = 200; }
public void TestForNodes() { ICollection <IClusterNode> nodes = _grid1.GetCluster().GetNodes(); IClusterNode first = nodes.ElementAt(0); IClusterNode second = nodes.ElementAt(1); IClusterGroup singleNodePrj = _grid1.GetCluster().ForNodeIds(first.Id); Assert.AreEqual(1, singleNodePrj.GetNodes().Count); Assert.AreEqual(first.Id, singleNodePrj.GetNodes().First().Id); singleNodePrj = _grid1.GetCluster().ForNodeIds(new List <Guid> { first.Id }); Assert.AreEqual(1, singleNodePrj.GetNodes().Count); Assert.AreEqual(first.Id, singleNodePrj.GetNodes().First().Id); singleNodePrj = _grid1.GetCluster().ForNodes(first); Assert.AreEqual(1, singleNodePrj.GetNodes().Count); Assert.AreEqual(first.Id, singleNodePrj.GetNodes().First().Id); singleNodePrj = _grid1.GetCluster().ForNodes(new List <IClusterNode> { first }); Assert.AreEqual(1, singleNodePrj.GetNodes().Count); Assert.AreEqual(first.Id, singleNodePrj.GetNodes().First().Id); IClusterGroup multiNodePrj = _grid1.GetCluster().ForNodeIds(first.Id, second.Id); Assert.AreEqual(2, multiNodePrj.GetNodes().Count); Assert.IsTrue(multiNodePrj.GetNodes().Contains(first)); Assert.IsTrue(multiNodePrj.GetNodes().Contains(second)); multiNodePrj = _grid1.GetCluster().ForNodeIds(new[] { first, second }.Select(x => x.Id)); Assert.AreEqual(2, multiNodePrj.GetNodes().Count); Assert.IsTrue(multiNodePrj.GetNodes().Contains(first)); Assert.IsTrue(multiNodePrj.GetNodes().Contains(second)); multiNodePrj = _grid1.GetCluster().ForNodes(first, second); Assert.AreEqual(2, multiNodePrj.GetNodes().Count); Assert.IsTrue(multiNodePrj.GetNodes().Contains(first)); Assert.IsTrue(multiNodePrj.GetNodes().Contains(second)); multiNodePrj = _grid1.GetCluster().ForNodes(new List <IClusterNode> { first, second }); Assert.AreEqual(2, multiNodePrj.GetNodes().Count); Assert.IsTrue(multiNodePrj.GetNodes().Contains(first)); Assert.IsTrue(multiNodePrj.GetNodes().Contains(second)); }
internal override async Task BootstrapAsync(IClusterNode node) { node.Owner = this; //fetch the cluster map to avoid race condition with streaming http BucketConfig = await _httpClusterMap.GetClusterMapAsync( Name, node.BootstrapUri, CancellationToken.None).ConfigureAwait(false); KeyMapper = new KetamaKeyMapper(BucketConfig, Context.ClusterOptions); //the initial bootstrapping endpoint; await node.SelectBucket(Name).ConfigureAwait(false); LoadManifest(); await Task.Run(async() => await Context.ProcessClusterMapAsync(this, BucketConfig)); }
private void CalculateStatistics(IClusterNode n, int round, double [] minClusters, double [] maxClusters) { if (round == 4) { return; } int clustersCount = n.ChildrenCount; minClusters[round] = Math.Min(minClusters[round], clustersCount); maxClusters[round] = Math.Max(maxClusters[round], clustersCount); for (int c = 0; c < n.ChildrenCount; ++c) { CalculateStatistics(n.GetChild(c), round + 1, minClusters, maxClusters); } }
/// <summary> /// Writes job map. /// </summary> /// <param name="writer">Writer.</param> /// <param name="map">Map</param> /// <returns>Job handle list.</returns> private static List <long> WriteJobs(BinaryWriter writer, IDictionary <IComputeJob <T>, IClusterNode> map) { Debug.Assert(writer != null && map != null); writer.WriteInt(map.Count); // Amount of mapped jobs. var jobHandles = new List <long>(map.Count); var ignite = writer.Marshaller.Ignite; try { foreach (KeyValuePair <IComputeJob <T>, IClusterNode> mapEntry in map) { var job = new ComputeJobHolder(ignite, mapEntry.Key.ToNonGeneric()); IClusterNode node = mapEntry.Value; var jobHandle = ignite.HandleRegistry.Allocate(job); jobHandles.Add(jobHandle); writer.WriteLong(jobHandle); if (node.IsLocal) { writer.WriteBoolean(false); // Job is not serialized. } else { writer.WriteBoolean(true); // Job is serialized. writer.WriteObject(job); } writer.WriteGuid(node.Id); } } catch (Exception) { foreach (var handle in jobHandles) { ignite.HandleRegistry.Release(handle); } throw; } return(jobHandles); }
internal override async Task BootstrapAsync(IClusterNode node) { //fetch the cluster map to avoid race condition with streaming http BucketConfig = await _httpClusterMap.GetClusterMapAsync( Name, node.BootstrapEndpoint, CancellationToken.None).ConfigureAwait(false); KeyMapper = await _ketamaKeyMapperFactory.CreateAsync(BucketConfig); //the initial bootstrapping endpoint; await node.SelectBucketAsync(this).ConfigureAwait(false); LoadManifest(); await Context.ProcessClusterMapAsync(this, BucketConfig); Bootstrapper.Start(this); }
/// <summary> /// Checks that node info is up to date. /// </summary> // ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local private static void CheckUpdatedNodes(IIgnite client, IClusterNode localNode, ICollection <IClusterNode> nodes) { var localNodeNew = client.GetCluster().GetLocalNode(); Assert.AreNotSame(localNode, localNodeNew); Assert.AreNotEqual(localNode.Id, localNodeNew.Id); var nodesNew = client.GetCluster().GetNodes(); Assert.AreEqual(2, nodesNew.Count); foreach (var node in nodesNew) { Assert.IsFalse(nodes.Any(n => n.Id == node.Id)); } }
/// <summary> /// Constructor. /// </summary> /// <param name="r">The reader to read data from.</param> internal CacheEvent(IBinaryRawReader r) : base(r) { _cacheName = r.ReadString(); _partition = r.ReadInt(); _isNear = r.ReadBoolean(); _eventNode = ReadNode(r); _key = r.ReadObject <object>(); _xid = IgniteGuid.Read(r); _newValue = r.ReadObject <object>(); _oldValue = r.ReadObject <object>(); _hasOldValue = r.ReadBoolean(); _hasNewValue = r.ReadBoolean(); _subjectId = r.ReadGuid(); _closureClassName = r.ReadString(); _taskName = r.ReadString(); }
private async Task <T> ExecuteOnOneNode <T>(IClusterNode node, string jobClassName, object[] args) { IgniteArgumentCheck.NotNull(node, nameof(node)); // Try direct connection to the specified node. if (_socket.GetEndpoint(node.Name) is { } endpoint) { using var writerWithoutNode = new PooledArrayBufferWriter(); Write(writerWithoutNode, writeNode: false); using var res1 = await _socket.TryDoOutInOpAsync(endpoint, ClientOp.ComputeExecute, writerWithoutNode) .ConfigureAwait(false); // Result is null when there was a connection issue, but retry policy allows another try. if (res1 != null) { return(Read(res1.Value)); } } // When direct connection is not available, use default connection and pass target node info to the server. using var writerWithNode = new PooledArrayBufferWriter(); Write(writerWithNode, writeNode: true); using var res2 = await _socket.DoOutInOpAsync(ClientOp.ComputeExecute, writerWithNode).ConfigureAwait(false); return(Read(res2)); void Write(PooledArrayBufferWriter writer, bool writeNode) { var w = writer.GetMessageWriter(); if (writeNode) { w.Write(node.Name); } else { w.WriteNil(); } w.Write(jobClassName); w.WriteObjectArrayWithTypes(args); w.Flush(); }
public void OnGenerateEnd(IClusterNode root) { if (IsVerbose) { int estimatedNodeCount = 1; int power = 1; for (int r = 0; r < 4; ++r) { power *= BucketCounts[r]; estimatedNodeCount += power; } int actualNodeCount = CountNodes <int> .Count <ClusterTree, IClusterNode>(null, root); Console.WriteLine("Nodes: estimated: {0:#,#}, actual: {1:#,#}", estimatedNodeCount, actualNodeCount); } }
/// <summary> /// Constructor. /// </summary> /// <param name="r">The reader to read data from.</param> internal CacheEvent(IPortableRawReader r) : base(r) { _cacheName = r.ReadString(); _partition = r.ReadInt(); _isNear = r.ReadBoolean(); _eventNode = ReadNode(r); _key = r.ReadObject<object>(); _xid = IgniteGuid.ReadPortable(r); _lockId = r.ReadObject<object>(); _newValue = r.ReadObject<object>(); _oldValue = r.ReadObject<object>(); _hasOldValue = r.ReadBoolean(); _hasNewValue = r.ReadBoolean(); _subjectId = r.ReadGuid() ?? Guid.Empty; _closureClassName = r.ReadString(); _taskName = r.ReadString(); }
/// <summary> /// Called when local client node has been disconnected from the cluster. /// </summary> internal void OnClientDisconnected() { // Clear cached node data. // Do not clear _nodes - it is in sync with PlatformContextImpl.sentNodes. _locNode = null; _prj.ClearCachedNodeData(); // Raise events. _clientReconnectTaskCompletionSource = new TaskCompletionSource <bool>(); var handler = ClientDisconnected; if (handler != null) { handler.Invoke(this, EventArgs.Empty); } }
public Bucket[] BucketizeHands(int round, McHand[] hands, IClusterNode parentNode) { KMeansNode parentKmNode = (KMeansNode)parentNode; if (hands == null || hands.Length == 0) { parentKmNode.AllocateChildren(1); parentKmNode.Children[0] = new KMeansNode(Dim, 0); return(new Bucket[] { new Bucket() }); } double[][] centers; double[][] values = CalcValuesAndKMeans(parentKmNode, round, hands, out centers); if (IsVerbose) { Console.Write("Centers:"); PrintCenters(centers); Console.WriteLine(); } Array.Sort(centers, new CenterComparer()); if (IsVerbose) { Console.Write("Sorted centers:"); PrintCenters(centers); Console.WriteLine(); } parentKmNode.AllocateChildren(centers.Length); for (int c = 0; c < centers.Length; ++c) { KMeansNode node = new KMeansNode(Dim, 0); centers[c].CopyTo(node.Center, 0); parentKmNode.Children[c] = node; } Bucket[] buckets = new Bucket[parentKmNode.Children.Length].Fill(i => new Bucket()); for (int i = 0; i < hands.Length; ++i) { // Never normalize values here, because it is either not necessary or already done (for k-means). int abstrCard = parentKmNode.FindClosestChild(values[i], false); buckets[abstrCard].Hands.Add(hands[i]); } return(buckets); }
internal override async Task BootstrapAsync(IClusterNode node) { node.Owner = this; await node.SelectBucket(this.Name); if (SupportsCollections) { Manifest = await node.GetManifest().ConfigureAwait(false); } //we still need to add a default collection LoadManifest(); BucketConfig = await node.GetClusterMap().ConfigureAwait(false); KeyMapper = new VBucketKeyMapper(BucketConfig); await Context.ProcessClusterMapAsync(this, BucketConfig); }
public void TestAffinityBinary() { IIgnite g = Ignition.GetIgnite("grid-0"); ICacheAffinity aff = g.GetAffinity("default"); IBinaryObject affKey = g.GetBinary().ToBinary <IBinaryObject>(new AffinityTestKey(0, 1)); IClusterNode node = aff.MapKeyToNode(affKey); for (int i = 0; i < 10; i++) { IBinaryObject otherAffKey = g.GetBinary().ToBinary <IBinaryObject>(new AffinityTestKey(i, 1)); Assert.AreEqual(node.Id, aff.MapKeyToNode(otherAffKey).Id); } }
public void TestAffinityPortable() { IIgnite g = Ignition.GetIgnite("grid-0"); ICacheAffinity aff = g.Affinity(null); IPortableObject affKey = g.Portables().ToPortable <IPortableObject>(new AffinityTestKey(0, 1)); IClusterNode node = aff.MapKeyToNode(affKey); for (int i = 0; i < 10; i++) { IPortableObject otherAffKey = g.Portables().ToPortable <IPortableObject>(new AffinityTestKey(i, 1)); Assert.AreEqual(node.Id, aff.MapKeyToNode(otherAffKey).Id); } }
protected EventBase(IBinaryRawReader r) { Debug.Assert(r != null); _id = r.ReadObject <IgniteGuid>(); _localOrder = r.ReadLong(); _node = ReadNode(r); _message = r.ReadString(); _type = r.ReadInt(); _name = r.ReadString(); var timestamp = r.ReadTimestamp(); Debug.Assert(timestamp.HasValue); _timestamp = timestamp.Value; }
public bool Connect(string endpoint) { if (Status == NodeStatus.Alive) { return(true); } try { string pipeName = "net.pipe://localhost/" + endpoint; pipeName = "net.tcp://" + endpoint + "/ServiceNode"; NetTcpBinding binding = new NetTcpBinding(); binding.ReceiveTimeout = TimeSpan.MaxValue; binding.ReliableSession.InactivityTimeout = TimeSpan.MaxValue; binding.ReliableSession.Enabled = true; if (channelFactory == null) { channelFactory = new ChannelFactory <IClusterNode>( binding, ///new NetNamedPipeBinding(), new EndpointAddress(pipeName)); } channel = channelFactory.CreateChannel(); ((IClientChannel)channel).Open(TimeSpan.FromMilliseconds(150)); ((IClientChannel)channel).Faulted += new EventHandler(ClientChannel_Falted); ((IClientChannel)channel).Closed += new EventHandler(ClientChannel_Closed); Status = NodeStatus.Alive; } catch (Exception) { Status = NodeStatus.Error; return(false); } return(true); }
/// <summary> /// Creates a new layout algorithm instance to operate on the given /// <paramref name="graph"/> using the given /// <see cref="IClusterNode"/> instance to affect the positions /// of the graph's nodes.</summary> /// <param name="graph">The graph that this layout algorithm will /// operate on by setting the positions of its nodes.</param> /// <param name="clusterNode">The <see cref="IClusterNode"/> /// instance that affects the positions of the nodes in the /// <paramref name="graph"/>.</param> /// <seealso cref="Graph"/><seealso cref="ClusterNode"/> public LayoutAlgorithm(Digraph <Node, Edge> graph, IClusterNode clusterNode) : base(graph) { if (clusterNode == null) { throw new ArgumentNullException("clusterNode"); } this.mClusterNode = clusterNode; this.mBBox = new Box2F(0, 0, 0, 0); uint vers = graph.NodeVersion; this.mLastNVers = vers == 0 ? uint.MaxValue : vers - 1; vers = graph.EdgeVersion; this.mLastEVers = vers == 0 ? uint.MaxValue : vers - 1; this.mLastXs = new float[0]; this.mLastYs = new float[0]; }
/// <summary> /// Creates a new layout algorithm instance to operate on the given /// <paramref name="graph"/> using the given <see cref="RectangleF"/> /// instance to constrain the positions of the graph's nodes to /// within its boundaries. /// </summary> /// <param name="graph">The graph that this layout algorithm will /// operate on by setting the positions of its nodes.</param> /// <param name="boundingBox">The <see cref="RectangleF"/> instance /// that constrains the positions of the nodes in the /// <paramref name="graph"/> to within its boundaries.</param> public LayoutAlgorithm(Digraph <Node, Edge> graph, Box2F boundingBox) : base(graph) { if (boundingBox == null) { throw new ArgumentNullException("boundingBox"); } this.mClusterNode = null; this.mBBox = boundingBox; uint vers = graph.NodeVersion; this.mLastNVers = vers == 0 ? uint.MaxValue : vers - 1; vers = graph.EdgeVersion; this.mLastEVers = vers == 0 ? uint.MaxValue : vers - 1; this.mLastXs = new float[0]; this.mLastYs = new float[0]; }
protected async Task CheckConnection(IClusterNode clusterNode) { //TODO temp fix for recreating dead connections - in future use CP to manage them var connection = clusterNode.Connection; if (connection.IsDead) { //recreate the connection its been closed and disposed connection = clusterNode.EndPoint.GetConnection(); clusterNode.ServerFeatures = await connection.Hello().ConfigureAwait(false); clusterNode.ErrorMap = await connection.GetErrorMap().ConfigureAwait(false); await connection.Authenticate(ClusterOptions, Name).ConfigureAwait(false); await connection.SelectBucket(Name).ConfigureAwait(false); clusterNode.Connection = connection; } }
public bool Connect(string endpoint) { if (Status == NodeStatus.Alive) return true; try { string pipeName = "net.pipe://localhost/" + endpoint; pipeName = "net.tcp://" + endpoint + "/ServiceNode"; NetTcpBinding binding = new NetTcpBinding(); binding.ReceiveTimeout = TimeSpan.MaxValue; binding.ReliableSession.InactivityTimeout = TimeSpan.MaxValue; binding.ReliableSession.Enabled = true; if (channelFactory == null) { channelFactory = new ChannelFactory<IClusterNode>( binding, ///new NetNamedPipeBinding(), new EndpointAddress(pipeName)); } channel = channelFactory.CreateChannel(); ((IClientChannel)channel).Open(TimeSpan.FromMilliseconds(150)); ((IClientChannel)channel).Faulted += new EventHandler(ClientChannel_Falted); ((IClientChannel)channel).Closed += new EventHandler(ClientChannel_Closed); Status = NodeStatus.Alive; } catch (Exception) { Status = NodeStatus.Error; return false; } return true; }
/** <inheritdoc /> */ public bool Invoke(IClusterNode node) { return node.Id == NodeId; }