Search in sources :

Example 1 with Master

use of org.neo4j.kernel.ha.Master 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)

Example 2 with Master

use of org.neo4j.kernel.ha.Master 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)

Aggregations

Master (org.neo4j.kernel.ha.Master)2 Machine (org.neo4j.kernel.ha.zookeeper.Machine)2 File (java.io.File)1 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 ComException (org.neo4j.com.ComException)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