public CCMCluster(CCMBridge cassandraCluster, Builder builder) { int tryNo = 0; this.Cluster = builder.AddContactPoints(IP_PREFIX + "1").Build(); RETRY: this.CassandraCluster = cassandraCluster; try { this.Session = Cluster.Connect(); if (tryNo > 0) { Cluster.RefreshSchema(); } } catch (NoHostAvailableException e) { if (tryNo < 10) { Console.WriteLine("CannotConnect to CCM node - give another try"); tryNo++; Thread.Sleep(1000); goto RETRY; } foreach (var entry in e.Errors) { Trace.TraceError("Error connecting to " + entry.Key + ": " + entry.Value); } throw new InvalidOperationException(null, e); } }
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 e) { // 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 e) {} } foreach(Host host in metadata.AllHosts()) { if (host.Address.Equals(address)) { if (testHost(host, waitForDead)) { return; } else { // 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){ return; } else { 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"); } }
private CCMCluster(CCMBridge ccmBridge, Builder builder) { int tryNo = 0; builder.AddContactPoints(Options.Default.IP_PREFIX + "1"); if (Options.Default.USE_COMPRESSION) { builder.WithCompression(CompressionType.Snappy); Console.WriteLine("Using Compression"); } if (Options.Default.USE_NOBUFFERING) { builder.WithoutRowSetBuffering(); Console.WriteLine("No buffering"); } this.Cluster = builder.Build(); RETRY: this.CCMBridge = ccmBridge; try { this.Session = Cluster.Connect(); if (tryNo > 0) { Cluster.RefreshSchema(); } } catch (NoHostAvailableException e) { if (tryNo < 10) { Console.WriteLine("CannotConnect to CCM node - give another try"); tryNo++; Thread.Sleep(1000); goto RETRY; } foreach (var entry in e.Errors) { Trace.TraceError("Error connecting to " + entry.Key + ": " + entry.Value); } throw new InvalidOperationException(null, e); } }
private CCMCluster(CCMBridge ccmBridge, Builder builder) { int tryNo = 0; builder.AddContactPoints(Options.Default.IP_PREFIX + "1"); if (Options.Default.USE_COMPRESSION) { builder.WithCompression(CompressionType.Snappy); Console.WriteLine("Using Compression"); } if (Options.Default.USE_NOBUFFERING) { builder.WithoutRowSetBuffering(); Console.WriteLine("No buffering"); } this.Cluster = builder.Build(); RETRY: this.CCMBridge = ccmBridge; try { this.Session = Cluster.Connect(); if(tryNo>0) Cluster.RefreshSchema(); } catch (NoHostAvailableException e) { if (tryNo < 10) { Console.WriteLine("CannotConnect to CCM node - give another try"); tryNo++; Thread.Sleep(1000); goto RETRY; } foreach (var entry in e.Errors) Trace.TraceError("Error connecting to " + entry.Key + ": " + entry.Value); throw new InvalidOperationException(null, e); } }
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 e) { // 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 e) { } } foreach (Host host in metadata.AllHosts()) { if (host.Address.Equals(address)) { if (testHost(host, waitForDead)) { return; } else { // 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) { return; } else { 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"); } }
public CCMCluster(CCMBridge cassandraCluster, Builder builder) { int tryNo = 0; this.Cluster = builder.AddContactPoints(IP_PREFIX + "1").Build(); RETRY: this.CassandraCluster = cassandraCluster; try { this.Session = Cluster.Connect(); if(tryNo>0) Cluster.RefreshSchema(); } catch (NoHostAvailableException e) { if (tryNo < 10) { Console.WriteLine("CannotConnect to CCM node - give another try"); tryNo++; Thread.Sleep(1000); goto RETRY; } foreach (var entry in e.Errors) Trace.TraceError("Error connecting to " + entry.Key + ": " + entry.Value); throw new InvalidOperationException(null, e); } }