Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract some session tracking functionality into a SessionTracker.
- Loading branch information
Showing
7 changed files
with
294 additions
and
88 deletions.
There are no files selected for viewing
103 changes: 103 additions & 0 deletions
103
enterprise/core-edge/src/main/java/org/neo4j/coreedge/ReplicationModule.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,103 @@ | ||
/* | ||
* Copyright (c) 2002-2016 "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.coreedge; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.UUID; | ||
import java.util.function.Supplier; | ||
|
||
import org.neo4j.coreedge.raft.ConsensusModule; | ||
import org.neo4j.coreedge.raft.RaftMessages; | ||
import org.neo4j.coreedge.raft.net.Outbound; | ||
import org.neo4j.coreedge.raft.replication.ProgressTrackerImpl; | ||
import org.neo4j.coreedge.raft.replication.RaftReplicator; | ||
import org.neo4j.coreedge.raft.replication.session.GlobalSession; | ||
import org.neo4j.coreedge.raft.replication.session.GlobalSessionTrackerState; | ||
import org.neo4j.coreedge.raft.replication.session.LocalSessionPool; | ||
import org.neo4j.coreedge.raft.replication.tx.ExponentialBackoffStrategy; | ||
import org.neo4j.coreedge.raft.state.DurableStateStorage; | ||
import org.neo4j.coreedge.server.CoreEdgeClusterSettings; | ||
import org.neo4j.coreedge.server.CoreMember; | ||
import org.neo4j.io.fs.FileSystemAbstraction; | ||
import org.neo4j.kernel.configuration.Config; | ||
import org.neo4j.kernel.impl.factory.PlatformModule; | ||
import org.neo4j.kernel.internal.DatabaseHealth; | ||
import org.neo4j.kernel.lifecycle.LifeSupport; | ||
import org.neo4j.logging.LogProvider; | ||
|
||
import static java.util.concurrent.TimeUnit.SECONDS; | ||
|
||
public class ReplicationModule | ||
{ | ||
private final RaftReplicator replicator; | ||
private final ProgressTrackerImpl progressTracker; | ||
private final SessionTracker sessionTracker; | ||
|
||
public ReplicationModule( CoreMember myself, PlatformModule platformModule, Config config, ConsensusModule consensusModule, | ||
Outbound<CoreMember,RaftMessages.RaftMessage> loggingOutbound, File clusterStateDirectory, | ||
FileSystemAbstraction fileSystem, Supplier<DatabaseHealth> databaseHealthSupplier, LogProvider logProvider ) | ||
{ | ||
LifeSupport life = platformModule.life; | ||
|
||
DurableStateStorage<GlobalSessionTrackerState> sessionTrackerStorage; | ||
try | ||
{ | ||
sessionTrackerStorage = life.add( | ||
new DurableStateStorage<>( fileSystem, new File( clusterStateDirectory, "session-tracker-state" ), | ||
"session-tracker", | ||
new GlobalSessionTrackerState.Marshal( new CoreMember.CoreMemberMarshal() ), | ||
config.get( CoreEdgeClusterSettings.global_session_tracker_state_size ), | ||
databaseHealthSupplier, logProvider ) ); | ||
|
||
} | ||
catch ( IOException e ) | ||
{ | ||
throw new RuntimeException( e ); | ||
} | ||
|
||
sessionTracker = new SessionTracker( sessionTrackerStorage ); | ||
|
||
GlobalSession myGlobalSession = new GlobalSession( UUID.randomUUID(), myself ); | ||
LocalSessionPool sessionPool = new LocalSessionPool( myGlobalSession ); | ||
progressTracker = new ProgressTrackerImpl( myGlobalSession ); | ||
|
||
replicator = new RaftReplicator( consensusModule.raftInstance(), myself, | ||
loggingOutbound, | ||
sessionPool, progressTracker, | ||
new ExponentialBackoffStrategy( 10, SECONDS ) ); | ||
|
||
} | ||
|
||
public RaftReplicator getReplicator() | ||
{ | ||
return replicator; | ||
} | ||
|
||
public ProgressTrackerImpl getProgressTracker() | ||
{ | ||
return progressTracker; | ||
} | ||
|
||
public SessionTracker getSessionTracker() | ||
{ | ||
return sessionTracker; | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
enterprise/core-edge/src/main/java/org/neo4j/coreedge/SessionTracker.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,84 @@ | ||
/* | ||
* Copyright (c) 2002-2016 "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.coreedge; | ||
|
||
import java.io.IOException; | ||
|
||
import org.neo4j.coreedge.catchup.storecopy.core.CoreStateType; | ||
import org.neo4j.coreedge.raft.replication.session.GlobalSession; | ||
import org.neo4j.coreedge.raft.replication.session.GlobalSessionTrackerState; | ||
import org.neo4j.coreedge.raft.replication.session.LocalOperationId; | ||
import org.neo4j.coreedge.raft.state.CoreSnapshot; | ||
import org.neo4j.coreedge.raft.state.StateStorage; | ||
|
||
public class SessionTracker implements SnapFlushable | ||
{ | ||
private final StateStorage<GlobalSessionTrackerState> sessionTrackerStorage; | ||
private GlobalSessionTrackerState sessionState = new GlobalSessionTrackerState(); | ||
|
||
public SessionTracker( StateStorage<GlobalSessionTrackerState> sessionTrackerStorage ) | ||
{ | ||
this.sessionTrackerStorage = sessionTrackerStorage; | ||
} | ||
|
||
public void start() | ||
{ | ||
sessionState = sessionTrackerStorage.getInitialState(); | ||
} | ||
|
||
@Override | ||
public long getLastAppliedIndex() | ||
{ | ||
return sessionState.logIndex(); | ||
} | ||
|
||
@Override | ||
public void flush() throws IOException | ||
{ | ||
sessionTrackerStorage.persistStoreData( sessionState ); | ||
} | ||
|
||
@Override | ||
public void addSnapshots( CoreSnapshot coreSnapshot ) | ||
{ | ||
coreSnapshot.add( CoreStateType.SESSION_TRACKER, sessionState.newInstance() ); | ||
} | ||
|
||
@Override | ||
public void installSnapshots( CoreSnapshot coreSnapshot ) | ||
{ | ||
sessionState = coreSnapshot.get( CoreStateType.SESSION_TRACKER ); | ||
} | ||
|
||
public boolean validateOperation( GlobalSession globalSession, LocalOperationId localOperationId ) | ||
{ | ||
return sessionState.validateOperation( globalSession, localOperationId ); | ||
} | ||
|
||
public void update( GlobalSession globalSession, LocalOperationId localOperationId, long logIndex ) | ||
{ | ||
sessionState.update( globalSession, localOperationId, logIndex ); | ||
} | ||
|
||
public GlobalSessionTrackerState newInstance() | ||
{ | ||
return sessionState.newInstance(); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
enterprise/core-edge/src/main/java/org/neo4j/coreedge/SnapFlushable.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,35 @@ | ||
/* | ||
* Copyright (c) 2002-2016 "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.coreedge; | ||
|
||
import java.io.IOException; | ||
|
||
import org.neo4j.coreedge.raft.state.CoreSnapshot; | ||
|
||
public interface SnapFlushable | ||
{ | ||
void flush() throws IOException; | ||
|
||
void addSnapshots( CoreSnapshot coreSnapshot ); | ||
|
||
long getLastAppliedIndex(); | ||
|
||
void installSnapshots( CoreSnapshot coreSnapshot ); | ||
} |
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.