Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
User-defined Upstream Selecton Strategy
Uses the same DSL as the load balancer to allow users to describe their upstream preferences.
- Loading branch information
Showing
16 changed files
with
274 additions
and
63 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
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
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
79 changes: 79 additions & 0 deletions
79
...rc/main/java/org/neo4j/causalclustering/readreplica/UserDefinedConfigurationStrategy.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,79 @@ | ||
/* | ||
* 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.Set; | ||
import java.util.stream.Collectors; | ||
|
||
import org.neo4j.causalclustering.core.CausalClusteringSettings; | ||
import org.neo4j.causalclustering.discovery.CoreServerInfo; | ||
import org.neo4j.causalclustering.discovery.CoreTopology; | ||
import org.neo4j.causalclustering.discovery.ReadReplicaInfo; | ||
import org.neo4j.causalclustering.identity.MemberId; | ||
import org.neo4j.causalclustering.load_balancing.filters.Filter; | ||
import org.neo4j.causalclustering.load_balancing.plugins.server_policies.FilterConfigParser; | ||
import org.neo4j.causalclustering.load_balancing.plugins.server_policies.InvalidFilterSpecification; | ||
import org.neo4j.causalclustering.load_balancing.plugins.server_policies.ServerInfo; | ||
import org.neo4j.helpers.Service; | ||
|
||
@Service.Implementation( UpstreamDatabaseSelectionStrategy.class ) | ||
public class UserDefinedConfigurationStrategy extends UpstreamDatabaseSelectionStrategy | ||
{ | ||
public UserDefinedConfigurationStrategy() | ||
{ | ||
super( "user-defined" ); | ||
} | ||
|
||
@Override | ||
public Optional<MemberId> upstreamDatabase() throws UpstreamDatabaseSelectionException | ||
{ | ||
try | ||
{ | ||
Filter<ServerInfo> filters = FilterConfigParser | ||
.parse( config.get( CausalClusteringSettings.user_defined_upstream_selection_strategy ) ); | ||
|
||
Set<ServerInfo> possibleReaders = topologyService.readReplicas().members().entrySet().stream() | ||
.map( entry -> new ServerInfo( entry.getValue().connectors().boltAddress(), entry.getKey(), | ||
entry.getValue().tags() ) ).collect( Collectors.toSet() ); | ||
|
||
CoreTopology coreTopology = topologyService.coreServers(); | ||
for ( MemberId validCore : coreTopology.members().keySet() ) | ||
{ | ||
Optional<CoreServerInfo> coreServerInfo = coreTopology.find( validCore ); | ||
if ( coreServerInfo.isPresent() ) | ||
{ | ||
CoreServerInfo serverInfo = coreServerInfo.get(); | ||
possibleReaders.add( | ||
new ServerInfo( serverInfo.connectors().boltAddress(), validCore, serverInfo.tags() ) ); | ||
} | ||
} | ||
|
||
return filters.apply( possibleReaders ).stream().map( ServerInfo::memberId ).findAny(); | ||
} | ||
catch ( InvalidFilterSpecification invalidFilterSpecification ) | ||
{ | ||
return Optional.empty(); | ||
} | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...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,2 +1,2 @@ | ||
org.neo4j.causalclustering.readreplica.ConnectToRandomCoreServer | ||
org.neo4j.causalclustering.readreplica.ConnectWithinDataCenter | ||
org.neo4j.causalclustering.readreplica.ConnectToRandomCoreServerStrategy | ||
org.neo4j.causalclustering.readreplica.ConnectWithinDataCenterStrategy |
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
Oops, something went wrong.