Skip to content

Additional logging around refresh of the routing table #287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
package org.neo4j.driver.internal.cluster;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.neo4j.driver.internal.NetworkSession;
import org.neo4j.driver.internal.net.BoltServerAddress;
import org.neo4j.driver.internal.spi.Connection;
import org.neo4j.driver.internal.util.Clock;
import org.neo4j.driver.v1.Logger;
import org.neo4j.driver.v1.Record;
import org.neo4j.driver.v1.Statement;
import org.neo4j.driver.v1.StatementResult;
Expand All @@ -45,29 +47,29 @@ final class Default implements Provider
{
private static final Statement GET_SERVER = new Statement( Provider.GET_SERVERS );
private final Clock clock;
private final Logger log;

Default( Clock clock )
Default( Clock clock, Logger log )
{
this.clock = clock;
this.log = log;
}

@Override
public ClusterComposition getClusterComposition( Connection connection ) throws ServiceUnavailableException
{
StatementResult cursor = getServers( connection );
List<Record> records = cursor.list();
log.info( "Got getServers response: %s", records );
long now = clock.millis();
try
{
if ( !cursor.hasNext() )
if ( records.size() != 1 )
{
return null; // server returned too few rows, this is a contract violation, treat as incapable
// server returned too few or too many rows, this is a contract violation, treat as incapable
return null;
}
Record record = cursor.next();
if ( cursor.hasNext() )
{
return null; // server returned too many rows, this is a contract violation, treat as incapable
}
return read( record, now );
return read( records.get( 0 ), now );
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public LoadBalancer(
ConnectionPool connections,
BoltServerAddress... routingAddresses ) throws ServiceUnavailableException
{
this( settings, clock, log, connections, new ClusterComposition.Provider.Default( clock ), routingAddresses );
this( settings, clock, log, connections, new ClusterComposition.Provider.Default( clock, log ),
routingAddresses );
}

LoadBalancer(
Expand Down Expand Up @@ -118,6 +119,9 @@ private Connection acquireConnection( RoundRobinAddressSet servers ) throws Serv
}
catch ( ServiceUnavailableException e )
{
log.error( String.format( "Failed to refresh routing information using routing address %s",
address ), e );

forget( address );
}
}
Expand All @@ -129,6 +133,8 @@ private synchronized void ensureRouting() throws ServiceUnavailableException
{
if ( stale() )
{
log.info( "Routing information is stale. Ttl %s, currentTime %s, routers %s, writers %s, readers %s",
expirationTimeout, clock.millis(), routers, writers, readers );
try
{
// get a new routing table
Expand All @@ -143,6 +149,9 @@ private synchronized void ensureRouting() throws ServiceUnavailableException
{
connections.purge( address );
}

log.info( "Refreshed routing information. Ttl %s, routers %s, writers %s, readers %s",
expirationTimeout, routers, writers, readers );
}
catch ( InterruptedException e )
{
Expand Down Expand Up @@ -177,6 +186,7 @@ private ClusterComposition lookupRoutingTable() throws InterruptedException, Ser
try ( Connection connection = connections.acquire( address ) )
{
cluster = provider.getClusterComposition( connection );
log.info( "Got cluster composition %s", cluster );
}
catch ( Exception e )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.neo4j.driver.internal.cluster;

import java.util.Arrays;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;

Expand Down Expand Up @@ -128,6 +129,12 @@ public synchronized void remove( BoltServerAddress address )
}
}

@Override
public String toString()
{
return "RoundRobinAddressSet=" + Arrays.toString( addresses );
}

/** breaking encapsulation in order to perform white-box testing of boundary case */
void setOffset( int target )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,23 @@
*/
package org.neo4j.driver.internal.cluster;

import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.mockito.stubbing.Stubber;

import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.mockito.stubbing.Stubber;

import org.neo4j.driver.internal.EventHandler;
import org.neo4j.driver.internal.net.BoltServerAddress;
import org.neo4j.driver.internal.spi.Collector;
import org.neo4j.driver.internal.spi.Connection;
import org.neo4j.driver.internal.util.FakeClock;
import org.neo4j.driver.v1.Logger;
import org.neo4j.driver.v1.Value;
import org.neo4j.driver.v1.exceptions.ServiceUnavailableException;

Expand Down Expand Up @@ -148,7 +149,8 @@ public void shouldPropagateConnectionFailureExceptions() throws Exception

private ClusterComposition getClusterComposition()
{
return new ClusterComposition.Provider.Default( clock ).getClusterComposition( connection );
return new ClusterComposition.Provider.Default( clock, mock( Logger.class ) )
.getClusterComposition( connection );
}

private void keys( final String... keys )
Expand Down