Exemplo n.º 1
0
        private void NodeMonitor()
        {
            while (!_disposing)
            {
                var       deadNodes = new List <IRiakNode>();
                IRiakNode node      = null;
                while (_offlineNodes.TryDequeue(out node) && !_disposing)
                {
                    var result = node.UseConnection(c => c.PbcWriteRead(MessageCode.PingReq, MessageCode.PingResp));

                    if (result.IsSuccess)
                    {
                        _loadBalancer.AddNode(node);
                    }
                    else
                    {
                        deadNodes.Add(node);
                    }
                }

                if (!_disposing)
                {
                    foreach (var deadNode in deadNodes)
                    {
                        _offlineNodes.Enqueue(deadNode);
                    }

                    Thread.Sleep(_nodePollTime);
                }
            }
        }
Exemplo n.º 2
0
        private void NodeMonitor()
        {
            while (true)
            {
                ct.ThrowIfCancellationRequested();

                var       deadNodes = new List <IRiakNode>();
                IRiakNode node      = null;
                while (offlineNodes.TryDequeue(out node))
                {
                    ct.ThrowIfCancellationRequested();
                    var result = node.UseConnection(c => c.PbcWriteRead(MessageCode.RpbPingReq, MessageCode.RpbPingResp));

                    ct.ThrowIfCancellationRequested();
                    if (result.IsSuccess)
                    {
                        loadBalancer.AddNode(node);
                    }
                    else
                    {
                        deadNodes.Add(node);
                    }
                }

                foreach (var deadNode in deadNodes)
                {
                    ct.ThrowIfCancellationRequested();
                    offlineNodes.Enqueue(deadNode);
                }

                ct.WaitHandle.WaitOne(nodePollTime);
            }
        }
Exemplo n.º 3
0
        // try to re-add dead nodes, started by timer
        private void NodeMonitorCycle()
        {
            if (!_disposing)
            {
                _nodePollTimer.Change(_nodePollTime, Timeout.Infinite);

                // dequeue all offline nodes
                var       offlineList = new List <IRiakNode>();
                IRiakNode queueNode   = null;
                while (_offlineNodes.TryDequeue(out queueNode) && !_disposing)
                {
                    offlineList.Add(queueNode);
                }

                // try to ping all offline nodes
                foreach (var node in offlineList)
                {
                    if (!_disposing)
                    {
                        node.UseConnection(c => c.PbcWriteRead(MessageCode.PingReq, MessageCode.PingResp))
                        .ContinueWith((Task <RiakResult> finishedTask) => {
                            if (!_disposing)
                            {
                                lock (node)
                                {
                                    if (finishedTask.Result.IsSuccess)
                                    {
                                        _loadBalancer.AddNode(node);
                                    }
                                    else
                                    {
                                        if (!_offlineNodes.Contains(node))
                                        {
                                            _offlineNodes.Enqueue(node);
                                        }
                                    }
                                }
                            }
                        });
                    }
                }
            }
        }
Exemplo n.º 4
0
        private async void NodeMonitor()
        {
            while (!_disposing)
            {
                var       deadNodes = new List <IRiakNode>();
                IRiakNode node      = null;
                while (_offlineNodes.TryDequeue(out node) && !_disposing)
                {
                    try
                    {
                        var nodeToMonitor = node;

                        await
                        _riakConnection.PbcWriteRead(new RiakNodeEndpoint(nodeToMonitor), MessageCode.PingReq,
                                                     MessageCode.PingResp).ConfigureAwait(false);

                        _loadBalancer.AddNode(node);
                    }
                    catch (Exception)
                    {
                        try
                        {
                            node.ReleaseAll().ConfigureAwait(false).GetAwaiter().GetResult();
                        }
                        finally
                        {
                            deadNodes.Add(node);
                        }
                    }
                }

                if (!_disposing)
                {
                    foreach (var deadNode in deadNodes)
                    {
                        _offlineNodes.Enqueue(deadNode);
                    }

                    Thread.Sleep(_nodePollTime);
                }
            }
        }