@Override public void start0() throws Throwable { BoundState boundState = clusterBinder.bindToCluster(); raftMessageHandler.start( boundState.clusterId() ); boolean startedByDownloader = false; if ( boundState.snapshot().isPresent() ) { // this means that we bootstrapped the cluster CoreSnapshot snapshot = boundState.snapshot().get(); snapshotService.installSnapshot( snapshot ); } else { snapshotService.awaitState(); Optional<JobScheduler.JobHandle> downloadJob = downloadService.downloadJob(); if ( downloadJob.isPresent() ) { downloadJob.get().waitTermination(); startedByDownloader = true; } } if ( !startedByDownloader ) { localDatabase.start(); coreStateMachines.installCommitProcess( localDatabase.getCommitProcess() ); } applicationProcess.start(); raftMachine.postRecoveryActions(); }
@Override public synchronized void handle( RaftMessages.ReceivedInstantClusterIdAwareMessage<?> wrappedMessage ) { try { ConsensusOutcome outcome = raftMachine.handle( wrappedMessage.message() ); if ( outcome.needsFreshSnapshot() ) { Optional<JobScheduler.JobHandle> downloadJob = downloadService.scheduleDownload( catchupAddressProvider ); if ( downloadJob.isPresent() ) { downloadJob.get().waitTermination(); } } else { notifyCommitted( outcome.getCommitIndex() ); } } catch ( Throwable e ) { log.error( "Error handling message", e ); raftMachine.panic(); localDatabase.panic( e ); } }