Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Core state downloader will now retry indefinitely
When the raft message handler need a new snapshot it will schedule this on the downloader service. This will pause the application process until download is successful.
- Loading branch information
Showing
8 changed files
with
596 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
.../main/java/org/neo4j/causalclustering/core/state/snapshot/CoreStateDownloaderService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright (c) 2002-2017 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.causalclustering.core.state.snapshot; | ||
|
||
import org.neo4j.causalclustering.core.consensus.LeaderLocator; | ||
import org.neo4j.causalclustering.core.state.CommandApplicationProcess; | ||
import org.neo4j.kernel.impl.util.JobScheduler; | ||
import org.neo4j.logging.Log; | ||
import org.neo4j.logging.LogProvider; | ||
|
||
import static org.neo4j.kernel.impl.util.JobScheduler.SchedulingStrategy.POOLED; | ||
|
||
public class CoreStateDownloaderService | ||
{ | ||
static final String OPERATION_NAME = "download of snapshot"; | ||
|
||
private final JobScheduler jobScheduler; | ||
private final CoreStateDownloader downloader; | ||
private final CommandApplicationProcess applicationProcess; | ||
private final Log log; | ||
private PersistentSnapshotDownloader currentJob = null; | ||
private final JobScheduler.Group downloadSnapshotGroup; | ||
|
||
public CoreStateDownloaderService( JobScheduler jobScheduler, CoreStateDownloader downloader, | ||
CommandApplicationProcess applicationProcess, | ||
LogProvider logProvider ) | ||
{ | ||
this.jobScheduler = jobScheduler; | ||
this.downloader = downloader; | ||
this.applicationProcess = applicationProcess; | ||
this.log = logProvider.getLog( getClass() ); | ||
this.downloadSnapshotGroup = new JobScheduler.Group( "download snapshot", POOLED ); | ||
} | ||
|
||
public void scheduleDownload( LeaderLocator leaderLocator ) | ||
{ | ||
if ( currentJob == null || currentJob.hasCompleted() ) | ||
{ | ||
synchronized ( this ) | ||
{ | ||
if ( currentJob == null || currentJob.hasCompleted() ) | ||
{ | ||
currentJob = new PersistentSnapshotDownloader( leaderLocator, applicationProcess, downloader, log ); | ||
jobScheduler.schedule( downloadSnapshotGroup, currentJob ); | ||
} | ||
} | ||
} | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
...ain/java/org/neo4j/causalclustering/core/state/snapshot/PersistentSnapshotDownloader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* Copyright (c) 2002-2017 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.causalclustering.core.state.snapshot; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.locks.LockSupport; | ||
|
||
import org.neo4j.causalclustering.catchup.storecopy.StoreCopyFailedException; | ||
import org.neo4j.causalclustering.core.consensus.LeaderLocator; | ||
import org.neo4j.causalclustering.core.consensus.NoLeaderFoundException; | ||
import org.neo4j.causalclustering.core.state.CommandApplicationProcess; | ||
import org.neo4j.causalclustering.helper.ExponentialBackoffStrategy; | ||
import org.neo4j.causalclustering.helper.TimeoutStrategy; | ||
import org.neo4j.logging.Log; | ||
|
||
class PersistentSnapshotDownloader implements Runnable | ||
{ | ||
private final CommandApplicationProcess applicationProcess; | ||
private final LeaderLocator leaderLocator; | ||
private final CoreStateDownloader downloader; | ||
private final Log log; | ||
private final TimeoutStrategy.Timeout timeout; | ||
private State state; | ||
|
||
PersistentSnapshotDownloader( LeaderLocator leaderLocator, | ||
CommandApplicationProcess applicationProcess, CoreStateDownloader downloader, Log log, | ||
TimeoutStrategy.Timeout timeout ) | ||
{ | ||
this.applicationProcess = applicationProcess; | ||
this.leaderLocator = leaderLocator; | ||
this.downloader = downloader; | ||
this.log = log; | ||
this.timeout = timeout; | ||
this.state = State.INITIATED; | ||
} | ||
|
||
PersistentSnapshotDownloader( LeaderLocator leaderLocator, | ||
CommandApplicationProcess applicationProcess, CoreStateDownloader downloader, Log log ) | ||
{ | ||
this( leaderLocator, applicationProcess, downloader, log, | ||
new ExponentialBackoffStrategy( 1, 30, TimeUnit.SECONDS ).newTimeout() ); | ||
} | ||
|
||
private enum State | ||
{ | ||
INITIATED, | ||
RUNNING, | ||
COMPLETED | ||
} | ||
|
||
@Override | ||
public void run() | ||
{ | ||
state = State.RUNNING; | ||
try | ||
{ | ||
applicationProcess.pauseApplier( CoreStateDownloaderService.OPERATION_NAME ); | ||
while ( true ) | ||
{ | ||
if ( Thread.interrupted() ) | ||
{ | ||
break; | ||
} | ||
try | ||
{ | ||
downloader.downloadSnapshot( leaderLocator.getLeader() ); | ||
applicationProcess.resumeApplier( CoreStateDownloaderService.OPERATION_NAME ); | ||
break; | ||
} | ||
catch ( StoreCopyFailedException e ) | ||
{ | ||
log.error( "Failed to download snapshot. Retrying in {} ms.", timeout.getMillis(), e ); | ||
} | ||
catch ( NoLeaderFoundException e ) | ||
{ | ||
log.warn( "No leader found. Retrying in {} ms.", timeout.getMillis() ); | ||
} | ||
LockSupport.parkNanos( TimeUnit.MILLISECONDS.toNanos( timeout.getMillis() ) ); | ||
timeout.increment(); | ||
} | ||
} | ||
finally | ||
{ | ||
state = State.COMPLETED; | ||
} | ||
} | ||
|
||
boolean isRunning() | ||
{ | ||
return state == State.RUNNING; | ||
} | ||
|
||
boolean hasCompleted() | ||
{ | ||
return state == State.COMPLETED; | ||
} | ||
|
||
} |
Oops, something went wrong.