当前位置: 首页>>代码示例>>C#>>正文


C# Cluster.RefreshSchema方法代码示例

本文整理汇总了C#中Cluster.RefreshSchema方法的典型用法代码示例。如果您正苦于以下问题:C# Cluster.RefreshSchema方法的具体用法?C# Cluster.RefreshSchema怎么用?C# Cluster.RefreshSchema使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cluster的用法示例。


在下文中一共展示了Cluster.RefreshSchema方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WaitForMeta

        private static void WaitForMeta(string nodeHost, Cluster cluster, int maxTry, bool waitForUp)
        {
            string expectedFinalNodeState = "UP";
            if (!waitForUp)
                expectedFinalNodeState = "DOWN";
            for (int i = 0; i < maxTry; ++i)
            {
                try
                {
                    // Are all nodes in the cluster accounted for?
                    bool disconnected = !cluster.RefreshSchema();
                    if (disconnected)
                    {
                        string warnStr = "While waiting for host " + nodeHost + " to be " + expectedFinalNodeState + ", the cluster is now totally down, returning now ... ";
                        Trace.TraceWarning(warnStr);
                        return;
                    }

                    Metadata metadata = cluster.Metadata;
                    foreach (Host host in metadata.AllHosts())
                    {
                        bool hostFound = false;
                        if (host.Address.ToString() == nodeHost)
                        {
                            hostFound = true;
                            if (host.IsUp && waitForUp)
                            {
                                Trace.TraceInformation("Verified according to cluster meta that host " + nodeHost + " is " + expectedFinalNodeState + ", returning now ... ");
                                return;
                            }
                            Trace.TraceWarning("We're waiting for host " + nodeHost + " to be " + expectedFinalNodeState);
                        }
                        // Is the host even in the meta list?
                        if (!hostFound)
                        {
                            if (!waitForUp)
                            {
                                Trace.TraceInformation("Verified according to cluster meta that host " + host.Address + " is not available in the MetaData hosts list, returning now ... ");
                                return;
                            }
                            else
                                Trace.TraceWarning("We're waiting for host " + nodeHost + " to be " + expectedFinalNodeState + ", but this host was not found in the MetaData hosts list!");
                        }
                    }
                }
                catch (Exception e)
                {
                    if (e.Message.Contains("None of the hosts tried for query are available") && !waitForUp)
                    {
                        Trace.TraceInformation("Verified according to cluster meta that host " + nodeHost + " is not available in the MetaData hosts list, returning now ... ");
                        return;
                    }
                    Trace.TraceInformation("Exception caught while waiting for meta data: " + e.Message);
                }
                Trace.TraceWarning("Waiting for node host: " + nodeHost + " to be " + expectedFinalNodeState);
                Thread.Sleep(DefaultSleepIterationMs);
            }
            string errStr = "Node host should have been " + expectedFinalNodeState + " but was not after " + maxTry + " tries!";
            Trace.TraceError(errStr);
        }
开发者ID:mtf30rob,项目名称:csharp-driver,代码行数:60,代码来源:TestUtils.cs

示例2: waitFor

        private static void waitFor(string node, Cluster cluster, int maxTry, bool waitForDead, bool waitForOut)
        {
            // In the case where the we've killed the last node in the cluster, if we haven't
            // tried doing an actual query, the driver won't realize that last node is dead until'
            // keep alive kicks in, but that's a fairly long time. So we cheat and trigger a force'
            // the detection by forcing a request.
            bool disconnected = false;
            if (waitForDead || waitForOut)
                disconnected = !cluster.RefreshSchema(null, null);

            if (disconnected)
                return;

            IPAddress address;
            try
            {
                address = IPAddress.Parse(node);
            }
            catch (Exception)
            {
                // That's a problem but that's not *our* problem
                return;
            }

            Metadata metadata = cluster.Metadata;
            for (int i = 0; i < maxTry; ++i)
            {
                bool found = false;
                foreach (Host host in metadata.AllHosts())
                {
                    if (host.Address.Equals(address))
                    {
                        found = true;
                        if (testHost(host, waitForDead))
                            return;
                    }
                }
                if (waitForDead && !found)
                    return;
                try
                {
                    Thread.Sleep(1000);
                }
                catch (Exception)
                {
                }
            }

            foreach (Host host in metadata.AllHosts())
            {
                if (host.Address.Equals(address))
                {
                    if (testHost(host, waitForDead))
                    {
                        return;
                    }
                    // logging it because this give use the timestamp of when this happens
                    logger.Info(node + " is not " + (waitForDead ? "DOWN" : "UP") + " after " + maxTry + "s");
                    throw new InvalidOperationException(node + " is not " + (waitForDead ? "DOWN" : "UP") + " after " + maxTry + "s");
                }
            }

            if (waitForOut)
            {
            }
            logger.Info(node + " is not part of the cluster after " + maxTry + "s");
            throw new InvalidOperationException(node + " is not part of the cluster after " + maxTry + "s");
        }
开发者ID:rasmus-s,项目名称:csharp-driver,代码行数:68,代码来源:TestUtils.cs


注:本文中的Cluster.RefreshSchema方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。