Skip to content

Commit c6ec3c2

Browse files
authored
Merge pull request #287 from lutovich/1.1-logging-around-routing-table
Additional logging around refresh of the routing table
2 parents 53dc05b + 9c8640f commit c6ec3c2

File tree

4 files changed

+37
-16
lines changed

4 files changed

+37
-16
lines changed

driver/src/main/java/org/neo4j/driver/internal/cluster/ClusterComposition.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@
1919
package org.neo4j.driver.internal.cluster;
2020

2121
import java.util.HashSet;
22+
import java.util.List;
2223
import java.util.Set;
2324

2425
import org.neo4j.driver.internal.NetworkSession;
2526
import org.neo4j.driver.internal.net.BoltServerAddress;
2627
import org.neo4j.driver.internal.spi.Connection;
2728
import org.neo4j.driver.internal.util.Clock;
29+
import org.neo4j.driver.v1.Logger;
2830
import org.neo4j.driver.v1.Record;
2931
import org.neo4j.driver.v1.Statement;
3032
import org.neo4j.driver.v1.StatementResult;
@@ -45,29 +47,29 @@ final class Default implements Provider
4547
{
4648
private static final Statement GET_SERVER = new Statement( Provider.GET_SERVERS );
4749
private final Clock clock;
50+
private final Logger log;
4851

49-
Default( Clock clock )
52+
Default( Clock clock, Logger log )
5053
{
5154
this.clock = clock;
55+
this.log = log;
5256
}
5357

5458
@Override
5559
public ClusterComposition getClusterComposition( Connection connection ) throws ServiceUnavailableException
5660
{
5761
StatementResult cursor = getServers( connection );
62+
List<Record> records = cursor.list();
63+
log.info( "Got getServers response: %s", records );
5864
long now = clock.millis();
5965
try
6066
{
61-
if ( !cursor.hasNext() )
67+
if ( records.size() != 1 )
6268
{
63-
return null; // server returned too few rows, this is a contract violation, treat as incapable
69+
// server returned too few or too many rows, this is a contract violation, treat as incapable
70+
return null;
6471
}
65-
Record record = cursor.next();
66-
if ( cursor.hasNext() )
67-
{
68-
return null; // server returned too many rows, this is a contract violation, treat as incapable
69-
}
70-
return read( record, now );
72+
return read( records.get( 0 ), now );
7173
}
7274
finally
7375
{

driver/src/main/java/org/neo4j/driver/internal/cluster/LoadBalancer.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ public LoadBalancer(
5151
ConnectionPool connections,
5252
BoltServerAddress... routingAddresses ) throws ServiceUnavailableException
5353
{
54-
this( settings, clock, log, connections, new ClusterComposition.Provider.Default( clock ), routingAddresses );
54+
this( settings, clock, log, connections, new ClusterComposition.Provider.Default( clock, log ),
55+
routingAddresses );
5556
}
5657

5758
LoadBalancer(
@@ -118,6 +119,9 @@ private Connection acquireConnection( RoundRobinAddressSet servers ) throws Serv
118119
}
119120
catch ( ServiceUnavailableException e )
120121
{
122+
log.error( String.format( "Failed to refresh routing information using routing address %s",
123+
address ), e );
124+
121125
forget( address );
122126
}
123127
}
@@ -129,6 +133,8 @@ private synchronized void ensureRouting() throws ServiceUnavailableException
129133
{
130134
if ( stale() )
131135
{
136+
log.info( "Routing information is stale. Ttl %s, currentTime %s, routers %s, writers %s, readers %s",
137+
expirationTimeout, clock.millis(), routers, writers, readers );
132138
try
133139
{
134140
// get a new routing table
@@ -143,6 +149,9 @@ private synchronized void ensureRouting() throws ServiceUnavailableException
143149
{
144150
connections.purge( address );
145151
}
152+
153+
log.info( "Refreshed routing information. Ttl %s, routers %s, writers %s, readers %s",
154+
expirationTimeout, routers, writers, readers );
146155
}
147156
catch ( InterruptedException e )
148157
{
@@ -177,6 +186,7 @@ private ClusterComposition lookupRoutingTable() throws InterruptedException, Ser
177186
try ( Connection connection = connections.acquire( address ) )
178187
{
179188
cluster = provider.getClusterComposition( connection );
189+
log.info( "Got cluster composition %s", cluster );
180190
}
181191
catch ( Exception e )
182192
{

driver/src/main/java/org/neo4j/driver/internal/cluster/RoundRobinAddressSet.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
package org.neo4j.driver.internal.cluster;
2020

21+
import java.util.Arrays;
2122
import java.util.Set;
2223
import java.util.concurrent.atomic.AtomicInteger;
2324

@@ -128,6 +129,12 @@ public synchronized void remove( BoltServerAddress address )
128129
}
129130
}
130131

132+
@Override
133+
public String toString()
134+
{
135+
return "RoundRobinAddressSet=" + Arrays.toString( addresses );
136+
}
137+
131138
/** breaking encapsulation in order to perform white-box testing of boundary case */
132139
void setOffset( int target )
133140
{

driver/src/test/java/org/neo4j/driver/internal/cluster/ClusterCompositionProviderTest.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,23 @@
1818
*/
1919
package org.neo4j.driver.internal.cluster;
2020

21+
import org.junit.Test;
22+
import org.mockito.invocation.InvocationOnMock;
23+
import org.mockito.stubbing.Answer;
24+
import org.mockito.stubbing.Stubber;
25+
2126
import java.util.Collections;
2227
import java.util.HashMap;
2328
import java.util.HashSet;
2429
import java.util.Map;
2530
import java.util.Set;
2631

27-
import org.junit.Test;
28-
import org.mockito.invocation.InvocationOnMock;
29-
import org.mockito.stubbing.Answer;
30-
import org.mockito.stubbing.Stubber;
31-
3232
import org.neo4j.driver.internal.EventHandler;
3333
import org.neo4j.driver.internal.net.BoltServerAddress;
3434
import org.neo4j.driver.internal.spi.Collector;
3535
import org.neo4j.driver.internal.spi.Connection;
3636
import org.neo4j.driver.internal.util.FakeClock;
37+
import org.neo4j.driver.v1.Logger;
3738
import org.neo4j.driver.v1.Value;
3839
import org.neo4j.driver.v1.exceptions.ServiceUnavailableException;
3940

@@ -148,7 +149,8 @@ public void shouldPropagateConnectionFailureExceptions() throws Exception
148149

149150
private ClusterComposition getClusterComposition()
150151
{
151-
return new ClusterComposition.Provider.Default( clock ).getClusterComposition( connection );
152+
return new ClusterComposition.Provider.Default( clock, mock( Logger.class ) )
153+
.getClusterComposition( connection );
152154
}
153155

154156
private void keys( final String... keys )

0 commit comments

Comments
 (0)