Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a Data Center Local upstream strategy.
A sensible out of the box plugin for allowing read replicas to catch up from named others within their locality. Log the loaded strategies and their order of precedence. Does not catchup from self.
- Loading branch information
Showing
15 changed files
with
380 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...stering/src/main/java/org/neo4j/causalclustering/readreplica/ConnectWithinDataCenter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright (c) 2002-2017 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.causalclustering.readreplica; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.Random; | ||
import java.util.stream.Collectors; | ||
|
||
import org.neo4j.causalclustering.core.CausalClusteringSettings; | ||
import org.neo4j.causalclustering.discovery.ReadReplicaInfo; | ||
import org.neo4j.causalclustering.identity.MemberId; | ||
import org.neo4j.helpers.Service; | ||
|
||
@Service.Implementation(UpstreamDatabaseSelectionStrategy.class) | ||
public class ConnectWithinDataCenter extends UpstreamDatabaseSelectionStrategy | ||
{ | ||
private Random random = new Random();; | ||
|
||
public ConnectWithinDataCenter() | ||
{ | ||
super( "connect-within-data-center" ); | ||
} | ||
|
||
@Override | ||
public Optional<MemberId> upstreamDatabase() throws UpstreamDatabaseSelectionException | ||
{ | ||
Map<MemberId, ReadReplicaInfo> replicas = topologyService.readReplicas().replicaMembers(); | ||
|
||
List<String> tags = config.get( CausalClusteringSettings.server_tags ); | ||
if ( tags.isEmpty() ) | ||
{ | ||
return Optional.empty(); | ||
} | ||
|
||
String myTag = tags.get( 0 ); | ||
|
||
List<Map.Entry<MemberId, ReadReplicaInfo>> choices = replicas.entrySet().stream() | ||
.filter( entry -> entry.getValue().tags().contains( myTag ) && !entry.getKey().equals( myself ) ) | ||
.collect( Collectors.toList() ); | ||
|
||
if ( choices.isEmpty() ) | ||
{ | ||
return Optional.empty(); | ||
} | ||
else | ||
{ | ||
return Optional.of( choices.get( random.nextInt( choices.size() ) ).getKey() ); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...ETA-INF/services/org.neo4j.causalclustering.readreplica.UpstreamDatabaseSelectionStrategy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
org.neo4j.causalclustering.readreplica.ConnectToRandomCoreServer | ||
org.neo4j.causalclustering.readreplica.ConnectWithinDataCenter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.