Skip to content

Commit ea1827d

Browse files
committed
Handle write sessions
For write sessions we throw a SessionExpiredException on connection failures
1 parent d85a610 commit ea1827d

File tree

3 files changed

+86
-3
lines changed

3 files changed

+86
-3
lines changed

driver/src/main/java/org/neo4j/driver/internal/ClusterDriver.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
public class ClusterDriver extends BaseDriver
4242
{
43-
private static final String DISCOVER_MEMBERS = "dbms.cluster.discoverMembers";
43+
private static final String DISCOVER_MEMBERS = "dbms.cluster.discoverEndpointAcquisitionServers";
4444
private static final String ACQUIRE_ENDPOINTS = "dbms.cluster.acquireEndpoints";
4545

4646
private final Endpoints endpoints = new Endpoints();
@@ -210,7 +210,7 @@ public void accept( Connection connection )
210210
}
211211
}, clusterSettings, log );
212212
case WRITE:
213-
throw new UnsupportedOperationException();
213+
return new WriteNetworkSession( acquireConnection( mode ), clusterSettings, log );
214214
default:
215215
throw new UnsupportedOperationException();
216216
}
@@ -237,7 +237,7 @@ private synchronized Connection acquireConnection( SessionMode mode )
237237
@Override
238238
public void accept( Record record )
239239
{
240-
String serverMode = record.get( "mode" ).asString();
240+
String serverMode = record.get( "role" ).asString();
241241
if ( serverMode.equals( "READ" ) )
242242
{
243243
endpoints.readServer = new BoltServerAddress( record.get( "address" ).asString() );
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* Copyright (c) 2002-2016 "Neo Technology,"
3+
* Network Engine for Objects in Lund AB [http://neotechnology.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
package org.neo4j.driver.internal;
20+
21+
22+
import org.neo4j.driver.internal.spi.Connection;
23+
import org.neo4j.driver.v1.Logger;
24+
import org.neo4j.driver.v1.Statement;
25+
import org.neo4j.driver.v1.StatementResult;
26+
import org.neo4j.driver.v1.exceptions.ConnectionFailureException;
27+
import org.neo4j.driver.v1.exceptions.SessionExpiredException;
28+
29+
public class WriteNetworkSession extends NetworkSession
30+
{
31+
32+
WriteNetworkSession(Connection connection, ClusterSettings clusterSettings, Logger logger )
33+
{
34+
super(connection, logger);
35+
}
36+
37+
@Override
38+
public StatementResult run( Statement statement )
39+
{
40+
try
41+
{
42+
return super.run( statement );
43+
}//TODO we need to catch exceptions due to leader switches etc here
44+
catch ( ConnectionFailureException e )
45+
{
46+
throw new SessionExpiredException( "Failed to perform write load to server", e );
47+
}
48+
49+
}
50+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Copyright (c) 2002-2016 "Neo Technology,"
3+
* Network Engine for Objects in Lund AB [http://neotechnology.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
package org.neo4j.driver.v1.exceptions;
20+
21+
/**
22+
* A <em>SessionExpiredException</em> indicates that the session can no longer satisfy the criteria under which it
23+
* was acquired, e.g. a server no longer accepts write requests. A new session needs to be acquired from the driver
24+
* and all actions taken on the expired session must be replayed.
25+
* @since 1.1
26+
*/
27+
public class SessionExpiredException extends Neo4jException
28+
{
29+
public SessionExpiredException( String message, Throwable throwable )
30+
{
31+
super( message, throwable );
32+
}
33+
}

0 commit comments

Comments
 (0)