use of org.neo4j.kernel.ha.com.master.MasterServer in project neo4j by neo4j.
the class SwitchToMasterTest method switchToMasterShouldIgnoreWildcardInConfig.
@Test
public void switchToMasterShouldIgnoreWildcardInConfig() throws Exception {
// SwitchToMaster is used to advertise to the rest of the cluster and advertising 0.0.0.0 makes no sense
// given
Config config = Config.embeddedDefaults(stringMap(ClusterSettings.server_id.name(), "1", HaSettings.ha_server.name(), "0.0.0.0:6001"));
URI me = new URI("ha://127.0.0.1");
MasterServer masterServer = mock(MasterServer.class);
// when
when(masterServer.getSocketAddress()).thenReturn(new InetSocketAddress("192.168.1.1", 6001));
URI result = SwitchToMaster.getMasterUri(me, masterServer, config);
// then
assertEquals("Wrong address", "ha://192.168.1.1:6001?serverId=1", result.toString());
// when masterServer is 0.0.0.0
when(masterServer.getSocketAddress()).thenReturn(new InetSocketAddress(6001));
result = SwitchToMaster.getMasterUri(me, masterServer, config);
// then
assertEquals("Wrong address", "ha://127.0.0.1:6001?serverId=1", result.toString());
}
use of org.neo4j.kernel.ha.com.master.MasterServer in project neo4j by neo4j.
the class SwitchToMaster method switchToMaster.
/**
* Performs a switch to the master state. Starts communication endpoints, switches components to the master state
* and broadcasts the appropriate Master Is Available event.
* @param haCommunicationLife The LifeSupport instance to register communication endpoints.
* @param me The URI that the communication endpoints should bind to
* @return The URI at which the master communication was bound.
*/
public URI switchToMaster(LifeSupport haCommunicationLife, URI me) {
userLog.info("I am %s, moving to master", myId(config));
// Do not wait for currently active transactions to complete before continuing switching.
// - A master in a cluster is very important, without it the cluster cannot process any write requests
// - Awaiting open transactions to complete assumes that this instance just now was a slave that is
// switching to master, which means the previous master where these active transactions were hosted
// is no longer available so these open transactions cannot continue and complete anyway,
// so what's the point waiting for them?
// - Read transactions may still be able to complete, but the correct response to failures in those
// is to have them throw transient error exceptions hinting that they should be retried,
// at which point they may get redirected to another instance, or to this instance if it has completed
// the switch until then.
idGeneratorFactory.switchToMaster();
NeoStoreDataSource neoStoreXaDataSource = dataSourceSupplier.get();
neoStoreXaDataSource.afterModeSwitch();
ConversationManager conversationManager = conversationManagerFactory.newInstance();
Master master = masterFactory.apply(conversationManager, haCommunicationLife);
MasterServer masterServer = masterServerFactory.apply(master, conversationManager);
haCommunicationLife.add(masterServer);
masterDelegateHandler.setDelegate(master);
haCommunicationLife.start();
URI masterHaURI = getMasterUri(me, masterServer, config);
clusterMemberAvailability.memberIsAvailable(MASTER, masterHaURI, neoStoreXaDataSource.getStoreId());
userLog.info("I am %s, successfully moved to master", myId(config));
slaveFactorySupplier.get().setStoreId(neoStoreXaDataSource.getStoreId());
return masterHaURI;
}
use of org.neo4j.kernel.ha.com.master.MasterServer in project neo4j by neo4j.
the class SwitchToMasterTest method switchToMasterShouldUseConfigSettingIfSuitable.
@Test
public void switchToMasterShouldUseConfigSettingIfSuitable() throws Exception {
// given
Config config = Config.embeddedDefaults(stringMap(ClusterSettings.server_id.name(), "1", HaSettings.ha_server.name(), "192.168.1.99:6001"));
URI me = new URI("ha://127.0.0.1");
MasterServer masterServer = mock(MasterServer.class);
// when
when(masterServer.getSocketAddress()).thenReturn(new InetSocketAddress("192.168.1.1", 6001));
URI result = SwitchToMaster.getMasterUri(me, masterServer, config);
// then
assertEquals("Wrong address", "ha://192.168.1.99:6001?serverId=1", result.toString());
}
use of org.neo4j.kernel.ha.com.master.MasterServer in project neo4j by neo4j.
the class SwitchToMasterTest method switchToMasterShouldHandleNoIpInConfig.
@Test
public void switchToMasterShouldHandleNoIpInConfig() throws Exception {
Config config = Config.embeddedDefaults(stringMap(ClusterSettings.server_id.name(), "1", HaSettings.ha_server.name(), ":6001"));
MasterServer masterServer = mock(MasterServer.class);
URI me = new URI("ha://127.0.0.1");
// when
when(masterServer.getSocketAddress()).thenReturn(new InetSocketAddress("192.168.1.1", 6001));
URI result = SwitchToMaster.getMasterUri(me, masterServer, config);
// then
assertEquals("Wrong address", "ha://192.168.1.1:6001?serverId=1", result.toString());
// when masterServer is 0.0.0.0
when(masterServer.getSocketAddress()).thenReturn(new InetSocketAddress(6001));
result = SwitchToMaster.getMasterUri(me, masterServer, config);
// then
assertEquals("Wrong address", "ha://127.0.0.1:6001?serverId=1", result.toString());
}
Aggregations