Search in sources :

Example 1 with ConversationManager

use of org.neo4j.kernel.ha.com.master.ConversationManager 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;
}
Also used : Master(org.neo4j.kernel.ha.com.master.Master) NeoStoreDataSource(org.neo4j.kernel.NeoStoreDataSource) ConversationManager(org.neo4j.kernel.ha.com.master.ConversationManager) URI(java.net.URI) MasterServer(org.neo4j.kernel.ha.com.master.MasterServer)

Aggregations

URI (java.net.URI)1 NeoStoreDataSource (org.neo4j.kernel.NeoStoreDataSource)1 ConversationManager (org.neo4j.kernel.ha.com.master.ConversationManager)1 Master (org.neo4j.kernel.ha.com.master.Master)1 MasterServer (org.neo4j.kernel.ha.com.master.MasterServer)1