Search in sources :

Example 1 with MasterClient

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

the class AbstractZooKeeperManager method invalidateMaster.

private void invalidateMaster() {
    if (cachedMaster != null) {
        MasterClient client = (MasterClient) cachedMaster.first();
        if (client != null) {
            client.shutdown();
        }
        cachedMaster = Pair.<Master, Machine>of(null, Machine.NO_MACHINE);
    }
}
Also used : MasterClient(org.neo4j.kernel.ha.MasterClient)

Example 2 with MasterClient

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

the class StandaloneDatabase method withFakeBroker.

public static StandaloneDatabase withFakeBroker(String testMethodName, final File path, int machineId, final int masterId, String[] extraArgs) {
    StandaloneDatabase standalone = new StandaloneDatabase(testMethodName, new Bootstrap(path, machineId) {

        @Override
        HighlyAvailableGraphDatabase start(String storeDir, Map<String, String> config) {
            final PlaceHolderGraphDatabaseService placeHolderGraphDb = new PlaceHolderGraphDatabaseService(path.getAbsolutePath());
            final Broker broker;
            if (machineId == masterId) {
                broker = new FakeMasterBroker(machineId, placeHolderGraphDb);
            } else {
                broker = new FakeSlaveBroker(new MasterClient("localhost", Protocol.PORT, placeHolderGraphDb), masterId, machineId, placeHolderGraphDb);
            }
            HighlyAvailableGraphDatabase db = new HighlyAvailableGraphDatabase(storeDir, config, AbstractHaTest.wrapBrokerAndSetPlaceHolderDb(placeHolderGraphDb, broker));
            placeHolderGraphDb.setDb(db);
            System.out.println("Started HA db (w/o zoo keeper)");
            return db;
        }
    });
    standalone.awaitStarted();
    return standalone;
}
Also used : Broker(org.neo4j.kernel.ha.Broker) FakeMasterBroker(org.neo4j.kernel.ha.FakeMasterBroker) FakeSlaveBroker(org.neo4j.kernel.ha.FakeSlaveBroker) HighlyAvailableGraphDatabase(org.neo4j.kernel.HighlyAvailableGraphDatabase) MasterClient(org.neo4j.kernel.ha.MasterClient) FakeSlaveBroker(org.neo4j.kernel.ha.FakeSlaveBroker) FakeMasterBroker(org.neo4j.kernel.ha.FakeMasterBroker) PlaceHolderGraphDatabaseService(slavetest.PlaceHolderGraphDatabaseService)

Example 3 with MasterClient

use of org.neo4j.kernel.ha.MasterClient 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 4 with MasterClient

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

the class AbstractZooKeeperManager method getMasterFromZooKeeper.

protected Pair<Master, Machine> getMasterFromZooKeeper(boolean wait) {
    Machine master = getMasterBasedOn(getAllMachines(wait).values());
    MasterClient masterClient = null;
    if (cachedMaster.other().getMachineId() != master.getMachineId()) {
        invalidateMaster();
        if (master != Machine.NO_MACHINE && master.getMachineId() != getMyMachineId()) {
            masterClient = new MasterClient(master, graphDb);
        }
        cachedMaster = Pair.<Master, Machine>of(masterClient, master);
    }
    return cachedMaster;
}
Also used : MasterClient(org.neo4j.kernel.ha.MasterClient)

Aggregations

MasterClient (org.neo4j.kernel.ha.MasterClient)4 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)1 HighlyAvailableGraphDatabase (org.neo4j.kernel.HighlyAvailableGraphDatabase)1 AbstractBroker (org.neo4j.kernel.ha.AbstractBroker)1 Broker (org.neo4j.kernel.ha.Broker)1 FakeMasterBroker (org.neo4j.kernel.ha.FakeMasterBroker)1 FakeSlaveBroker (org.neo4j.kernel.ha.FakeSlaveBroker)1 Master (org.neo4j.kernel.ha.Master)1 Machine (org.neo4j.kernel.ha.zookeeper.Machine)1 PlaceHolderGraphDatabaseService (slavetest.PlaceHolderGraphDatabaseService)1