Search in sources :

Example 1 with Machine

use of org.neo4j.kernel.ha.zookeeper.Machine in project graphdb by neo4j-attic.

the class HaBackupProvider method getMasterServerInCluster.

private static String getMasterServerInCluster(String from) {
    ClusterManager clusterManager = new ClusterManager(from);
    Pair<String, Integer> masterServer = null;
    try {
        clusterManager.waitForSyncConnected();
        Machine master = clusterManager.getMaster();
        masterServer = master.getServer();
        if (masterServer != null) {
            int backupPort = clusterManager.getBackupPort(master.getMachineId());
            return String.format(ServerAddressFormat, masterServer.first(), backupPort);
        }
        throw new ComException("Master couldn't be found from cluster managed by " + from);
    } finally {
        clusterManager.shutdown();
    }
}
Also used : ComException(org.neo4j.com.ComException) ClusterManager(org.neo4j.kernel.ha.zookeeper.ClusterManager) Machine(org.neo4j.kernel.ha.zookeeper.Machine)

Example 2 with Machine

use of org.neo4j.kernel.ha.zookeeper.Machine in project graphdb by neo4j-attic.

the class HighlyAvailableGraphDatabase method startUp.

private synchronized void startUp(boolean allowInit) {
    StoreId storeId = null;
    if (!new File(storeDir, "neostore").exists()) {
        long endTime = System.currentTimeMillis() + 10000;
        Exception exception = null;
        while (System.currentTimeMillis() < endTime) {
            // Check if the cluster is up
            Pair<Master, Machine> master = broker.getMaster();
            master = master.first() != null ? master : broker.getMasterReally();
            if (master != null && master.first() != null) {
                // Join the existing cluster
                try {
                    copyStoreFromMaster(master);
                    msgLog.logMessage("copied store from master");
                    exception = null;
                    break;
                } catch (Exception e) {
                    exception = e;
                    broker.getMasterReally();
                    msgLog.logMessage("Problems copying store from master", e);
                }
            } else if (allowInit) {
                // Try to initialize the cluster and become master
                exception = null;
                StoreId myStoreId = new StoreId();
                storeId = broker.createCluster(myStoreId);
                if (storeId.equals(myStoreId)) {
                    // I am master
                    break;
                }
            }
            // I am not master, and could not connect to the master:
            // wait for other machine(s) to join.
            sleepWithoutInterruption(300, "Startup interrupted");
        }
        if (exception != null) {
            throw new RuntimeException("Tried to join the cluster, but was unable to", exception);
        }
    }
    newMaster(null, storeId, new Exception());
    localGraph();
}
Also used : Master(org.neo4j.kernel.ha.Master) StoreId(org.neo4j.kernel.impl.nioneo.store.StoreId) File(java.io.File) ComException(org.neo4j.com.ComException) BranchedDataException(org.neo4j.kernel.ha.BranchedDataException) ZooKeeperException(org.neo4j.kernel.ha.zookeeper.ZooKeeperException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) Machine(org.neo4j.kernel.ha.zookeeper.Machine)

Example 3 with Machine

use of org.neo4j.kernel.ha.zookeeper.Machine in project graphdb by neo4j-attic.

the class DumpZooInfo method main.

public static void main(String[] args) {
    ClusterManager clusterManager = new ClusterManager("localhost");
    clusterManager.waitForSyncConnected();
    System.out.println("Master is " + clusterManager.getCachedMaster());
    System.out.println("Connected slaves");
    for (Machine info : clusterManager.getConnectedSlaves()) {
        System.out.println("\t" + info);
    }
    //        System.out.println( "Disconnected slaves" );
    //        for ( Machine info : clusterManager.getDisconnectedSlaves() )
    //        {
    //            System.out.println( "\t" + info );
    //        }
    clusterManager.shutdown();
}
Also used : ClusterManager(org.neo4j.kernel.ha.zookeeper.ClusterManager) Machine(org.neo4j.kernel.ha.zookeeper.Machine)

Example 4 with Machine

use of org.neo4j.kernel.ha.zookeeper.Machine in project graphdb by neo4j-attic.

the class SingleJvmWithNettyTest method makeSlaveBroker.

@Override
protected Broker makeSlaveBroker(MasterImpl master, int masterId, int id, GraphDatabaseService graphDb) {
    final Machine masterMachine = new //
    Machine(//
    masterId, //
    -1, //
    1, "localhost:" + Protocol.PORT);
    final Master client = new MasterClient(masterMachine, graphDb);
    return new AbstractBroker(id, graphDb) {

        public boolean iAmMaster() {
            return false;
        }

        public Pair<Master, Machine> getMasterReally() {
            return getMaster();
        }

        public Pair<Master, Machine> getMaster() {
            return Pair.of(client, masterMachine);
        }

        public Object instantiateMasterServer(GraphDatabaseService graphDb) {
            throw new UnsupportedOperationException("cannot instantiate master server on slave");
        }
    };
}
Also used : Master(org.neo4j.kernel.ha.Master) AbstractBroker(org.neo4j.kernel.ha.AbstractBroker) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) MasterClient(org.neo4j.kernel.ha.MasterClient) Machine(org.neo4j.kernel.ha.zookeeper.Machine)

Aggregations

Machine (org.neo4j.kernel.ha.zookeeper.Machine)4 ComException (org.neo4j.com.ComException)2 Master (org.neo4j.kernel.ha.Master)2 ClusterManager (org.neo4j.kernel.ha.zookeeper.ClusterManager)2 File (java.io.File)1 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)1 AbstractBroker (org.neo4j.kernel.ha.AbstractBroker)1 BranchedDataException (org.neo4j.kernel.ha.BranchedDataException)1 MasterClient (org.neo4j.kernel.ha.MasterClient)1 ZooKeeperException (org.neo4j.kernel.ha.zookeeper.ZooKeeperException)1 StoreId (org.neo4j.kernel.impl.nioneo.store.StoreId)1