Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
StoreCopy E_TOO_FAR_BEHIND response before async checkpoint
Performing a store copy against a machine that is too far behind will cause a checkpoint to be performed before the erroneous response is sent. This change sends the response first then asynchronously performs a checkpoint.
- Loading branch information
Showing
9 changed files
with
314 additions
and
72 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
community/common/src/main/java/org/neo4j/scheduler/LockingExecutor.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,55 @@ | |||
/* | |||
* Copyright (c) 2002-2018 "Neo4j," | |||
* Neo4j Sweden AB [http://neo4j.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 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 General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
package org.neo4j.scheduler; | |||
|
|||
import java.util.concurrent.Executor; | |||
import java.util.concurrent.atomic.AtomicBoolean; | |||
|
|||
public class LockingExecutor implements Executor | |||
{ | |||
private final JobScheduler jobScheduler; | |||
private final JobScheduler.Group group; | |||
private final AtomicBoolean latch = new AtomicBoolean( false ); | |||
|
|||
public LockingExecutor( JobScheduler jobScheduler, JobScheduler.Group group ) | |||
{ | |||
this.jobScheduler = jobScheduler; | |||
this.group = group; | |||
} | |||
|
|||
@Override | |||
public void execute( Runnable runnable ) | |||
{ | |||
if ( latch.compareAndSet( false, true ) ) | |||
{ | |||
jobScheduler.schedule( group, () -> | |||
{ | |||
try | |||
{ | |||
runnable.run(); | |||
} | |||
finally | |||
{ | |||
latch.set( false ); | |||
} | |||
} ); | |||
} | |||
} | |||
} |
70 changes: 70 additions & 0 deletions
70
...usal-clustering/src/main/java/org/neo4j/causalclustering/catchup/CheckPointerService.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,70 @@ | |||
/* | |||
* Copyright (c) 2002-2018 "Neo4j," | |||
* Neo4j Sweden AB [http://neo4j.com] | |||
* | |||
* This file is part of Neo4j Enterprise Edition. The included source | |||
* code can be redistributed and/or modified under the terms of the | |||
* GNU AFFERO GENERAL PUBLIC LICENSE Version 3 | |||
* (http://www.fsf.org/licensing/licenses/agpl-3.0.html) with the | |||
* Commons Clause, as found in the associated LICENSE.txt file. | |||
* | |||
* 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. | |||
* | |||
* Neo4j object code can be licensed independently from the source | |||
* under separate terms from the AGPL. Inquiries can be directed to: | |||
* licensing@neo4j.com | |||
* | |||
* More information is also available at: | |||
* https://neo4j.com/licensing/ | |||
*/ | |||
package org.neo4j.causalclustering.catchup; | |||
|
|||
import java.io.IOException; | |||
import java.util.concurrent.Executor; | |||
import java.util.function.Consumer; | |||
import java.util.function.Supplier; | |||
|
|||
import org.neo4j.kernel.impl.transaction.log.checkpoint.CheckPointer; | |||
import org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo; | |||
import org.neo4j.scheduler.JobScheduler; | |||
import org.neo4j.scheduler.LockingExecutor; | |||
|
|||
public class CheckPointerService | |||
{ | |||
private final Supplier<CheckPointer> checkPointerSupplier; | |||
private final Executor lockingCheckpointExecutor; | |||
|
|||
public CheckPointerService( Supplier<CheckPointer> checkPointerSupplier, JobScheduler jobScheduler, JobScheduler.Group group ) | |||
{ | |||
this.checkPointerSupplier = checkPointerSupplier; | |||
this.lockingCheckpointExecutor = new LockingExecutor( jobScheduler, group ); | |||
} | |||
|
|||
public CheckPointer getCheckPointer() | |||
{ | |||
return checkPointerSupplier.get(); | |||
} | |||
|
|||
public long lastCheckPointedTransactionId() | |||
{ | |||
return checkPointerSupplier.get().lastCheckPointedTransactionId(); | |||
} | |||
|
|||
public void tryAsyncCheckpoint( Consumer<IOException> exceptionHandler ) | |||
{ | |||
lockingCheckpointExecutor.execute( () -> | |||
{ | |||
try | |||
{ | |||
getCheckPointer().tryCheckPoint( new SimpleTriggerInfo( "Store file copy" ) ); | |||
} | |||
catch ( IOException e ) | |||
{ | |||
exceptionHandler.accept( e ); | |||
} | |||
} ); | |||
} | |||
} |
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
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
Oops, something went wrong.