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();
}
}
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();
}
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();
}
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");
}
};
}
Aggregations