Host connectedHost() { Connection current = connectionRef.get(); return (current == null) ? null : cluster.metadata.getHost(current.address); }
<E extends Throwable> E defunct(E e) { if (isDefunct.compareAndSet(false, true)) { if (Host.statesLogger.isTraceEnabled()) Host.statesLogger.trace("Defuncting " + this, e); else if (Host.statesLogger.isDebugEnabled()) Host.statesLogger.debug("Defuncting {} because: {}", this, e.getMessage()); Host host = factory.manager.metadata.getHost(address); if (host != null) { // Sometimes close() can be called before defunct(); avoid decrementing the connection count // twice, but // we still want to signal the error to the conviction policy. boolean decrement = signaled.compareAndSet(false, true); boolean hostDown = host.convictionPolicy.signalConnectionFailure(this, decrement); if (hostDown) { factory.manager.signalHostDown(host, host.wasJustAdded()); } else { notifyOwnerWhenDefunct(); } } // Force the connection to close to make sure the future completes. Otherwise force() might // never get called and // threads will wait on the future forever. // (this also errors out pending handlers) closeAsync().force(); } return e; }
Host host = factory.manager.metadata.getHost(address); if (host != null) { host.convictionPolicy.signalConnectionClosed(this);
protected Host retrieveSingleHost(Cluster cluster) { Host host = cluster.getMetadata().getHost(hostAddress); if (host == null) { fail("Unable to retrieve host"); } return host; }
switch (eventType) { case UP: Host upHost = metadata.getHost(address); if (upHost == null) { upHost = metadata.newHost(address); Host downHost = metadata.getHost(address); if (downHost != null) { Host removedHost = metadata.getHost(address); if (removedHost != null) futures.add(execute(hostRemoved(removedHost))); break;
private static boolean checkSchemaAgreement(Connection connection, Cluster.Manager cluster) throws InterruptedException, ExecutionException { DefaultResultSetFuture peersFuture = new DefaultResultSetFuture( null, cluster.protocolVersion(), new Requests.Query(SELECT_SCHEMA_PEERS)); DefaultResultSetFuture localFuture = new DefaultResultSetFuture( null, cluster.protocolVersion(), new Requests.Query(SELECT_SCHEMA_LOCAL)); connection.write(peersFuture); connection.write(localFuture); Set<UUID> versions = new HashSet<UUID>(); Row localRow = localFuture.get().one(); if (localRow != null && !localRow.isNull("schema_version")) versions.add(localRow.getUUID("schema_version")); for (Row row : peersFuture.get()) { InetSocketAddress addr = nativeAddressForPeerHost(row, connection.address, cluster); if (addr == null || row.isNull("schema_version")) continue; Host peer = cluster.metadata.getHost(addr); if (peer != null && peer.isUp()) versions.add(row.getUUID("schema_version")); } logger.debug("Checking for schema agreement: versions are {}", versions); return versions.size() <= 1; }
@Test(groups = "short") public void testMissingRpcAddressAtStartup() throws Exception { deleteNode2RpcAddressFromNode1(); // Use only one contact point to make sure that the control connection is on node1 Cluster cluster = register( Cluster.builder() .addContactPoints(getContactPoints().get(0)) .withPort(ccm().getBinaryPort()) .build()); cluster.connect(); // Since node2's RPC address is unknown on our control host, it should have been ignored assertEquals(cluster.getMetrics().getConnectedToHosts().getValue().intValue(), 1); assertNull(cluster.getMetadata().getHost(getContactPointsWithPorts().get(1))); }
final Host host = cluster().getMetadata().getHost(ccm().addressOfNode(1)); ScheduledExecutorService openConnectionsWatcherExecutor = Executors.newScheduledThreadPool(1); final Runnable openConnectionsWatcher =
throws ConnectionException, BusyConnectionException, ExecutionException, InterruptedException { Host host = cluster.metadata.getHost(connection.address);
Host connectedHost() { Connection current = connectionRef.get(); return (current == null) ? null : cluster.metadata.getHost(current.address); }
Host connectedHost() { Connection current = connectionRef.get(); return (current == null) ? null : cluster.metadata.getHost(current.address); }
Host connectedHost() { Connection current = connectionRef.get(); return (current == null) ? null : cluster.metadata.getHost(current.address); }
Host connectedHost() { Connection current = connectionRef.get(); return cluster.metadata.getHost(current.address); }
ConnectionException defunct(ConnectionException e) { if (logger.isDebugEnabled()) logger.debug("Defuncting connection to " + address, e); exception = e; isDefunct = true; dispatcher.errorOutAllHandler(e); Host host = factory.manager.metadata.getHost(address); if (host != null) { boolean isDown = factory.manager.signalConnectionFailure(host, e, host.wasJustAdded()); notifyOwnerWhenDefunct(isDown); } closeAsync(); return e; }
protected Host retrieveSingleHost(Cluster cluster) { Host host = cluster.getMetadata().getHost(hostAddress); if (host == null) { fail("Unable to retrieve host"); } return host; }
static void refreshSchema(Connection connection, SchemaElement targetType, String targetKeyspace, String targetName, List<String> targetSignature, Cluster.Manager cluster) throws ConnectionException, BusyConnectionException, ExecutionException, InterruptedException { Host host = cluster.metadata.getHost(connection.address); // Neither host, nor it's version should be null. But instead of dying if there is a race or something, we can kind of try to infer // a Cassandra version from the protocol version (this is not full proof, we can have the protocol 1 against C* 2.0+, but it's worth // a shot, and since we log in this case, it should be relatively easy to debug when if this ever fail). VersionNumber cassandraVersion; if (host == null || host.getCassandraVersion() == null) { cassandraVersion = cluster.protocolVersion().minCassandraVersion(); logger.warn("Cannot find Cassandra version for host {} to parse the schema, using {} based on protocol version in use. " + "If parsing the schema fails, this could be the cause", connection.address, cassandraVersion); } else { cassandraVersion = host.getCassandraVersion(); } SchemaParser.forVersion(cassandraVersion) .refresh(cluster.getCluster(), targetType, targetKeyspace, targetName, targetSignature, connection, cassandraVersion); }
static void refreshSchema(Connection connection, SchemaElement targetType, String targetKeyspace, String targetName, List<String> targetSignature, Cluster.Manager cluster) throws ConnectionException, BusyConnectionException, ExecutionException, InterruptedException { Host host = cluster.metadata.getHost(connection.address); // Neither host, nor it's version should be null. But instead of dying if there is a race or something, we can kind of try to infer // a Cassandra version from the protocol version (this is not full proof, we can have the protocol 1 against C* 2.0+, but it's worth // a shot, and since we log in this case, it should be relatively easy to debug when if this ever fail). VersionNumber cassandraVersion; if (host == null || host.getCassandraVersion() == null) { cassandraVersion = cluster.protocolVersion().minCassandraVersion(); logger.warn("Cannot find Cassandra version for host {} to parse the schema, using {} based on protocol version in use. " + "If parsing the schema fails, this could be the cause", connection.address, cassandraVersion); } else { cassandraVersion = host.getCassandraVersion(); } SchemaParser.forVersion(cassandraVersion) .refresh(cluster.getCluster(), targetType, targetKeyspace, targetName, targetSignature, connection, cassandraVersion); }
@Test(groups = "short") public void testMissingRpcAddressAtStartup() throws Exception { deleteNode2RpcAddressFromNode1(); // Use only one contact point to make sure that the control connection is on node1 Cluster cluster = register( Cluster.builder() .addContactPoints(getContactPoints().get(0)) .withPort(ccm().getBinaryPort()) .build()); cluster.connect(); // Since node2's RPC address is unknown on our control host, it should have been ignored assertEquals(cluster.getMetrics().getConnectedToHosts().getValue().intValue(), 1); assertNull(cluster.getMetadata().getHost(getContactPointsWithPorts().get(1))); }