Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduces state persistence for GlobalSessionTracker and LockTokenState
Another part of the builtup raft state that needs to be persisted is the tracking of tx sessions and the requests for locks. This commit makes these states persistent, using the same receipe of having InMemory and OnDisk implementations of the relevant state interface.
- Loading branch information
1 parent
eda2044
commit 42ee803
Showing
27 changed files
with
1,228 additions
and
328 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
113 changes: 0 additions & 113 deletions
113
...-edge/src/main/java/org/neo4j/coreedge/raft/replication/session/GlobalSessionTracker.java
This file was deleted.
Oops, something went wrong.
41 changes: 41 additions & 0 deletions
41
.../src/main/java/org/neo4j/coreedge/raft/replication/session/GlobalSessionTrackerState.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,41 @@ | ||
/* | ||
* 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.raft.replication.session; | ||
|
||
/** | ||
* Each cluster instance has a global session as well as several local sessions. Each local session | ||
* tracks its operation by assigning a unique sequence number to each operation. This allows | ||
* an operation originating from an instance to be uniquely identified and duplicate attempts | ||
* at performing that operation can be filtered out. | ||
* <p> | ||
* The session tracker defines the strategy for which local operations are allowed to be performed | ||
* and the strategy is to only allow operations to occur in strict order, that is with no gaps, | ||
* starting with sequence number zero. This is done for reasons of efficiency and creates a very | ||
* direct coupling between session tracking and operation validation. This class is in charge | ||
* of both. | ||
*/ | ||
public interface GlobalSessionTrackerState<MEMBER> | ||
{ | ||
/** | ||
* Tracks the operation and returns true iff this operation should be allowed. | ||
*/ | ||
boolean validateAndTrackOperationAtLogIndex( GlobalSession<MEMBER> globalSession, LocalOperationId localOperationId, | ||
long logIndex ); | ||
} |
61 changes: 61 additions & 0 deletions
61
...org/neo4j/coreedge/raft/replication/session/GlobalSessionTrackerStateRecoveryManager.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,61 @@ | ||
/* | ||
* 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.raft.replication.session; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
import org.neo4j.coreedge.raft.state.StateRecoveryManager; | ||
import org.neo4j.io.fs.FileSystemAbstraction; | ||
import org.neo4j.kernel.impl.transaction.log.ReadAheadChannel; | ||
import org.neo4j.storageengine.api.ReadableChannel; | ||
|
||
public class GlobalSessionTrackerStateRecoveryManager<MEMBER> extends StateRecoveryManager | ||
{ | ||
private final InMemoryGlobalSessionTrackerState.InMemoryGlobalSessionTrackerStateChannelMarshal<MEMBER> marshal; | ||
|
||
public GlobalSessionTrackerStateRecoveryManager( FileSystemAbstraction fileSystem, | ||
InMemoryGlobalSessionTrackerState.InMemoryGlobalSessionTrackerStateChannelMarshal<MEMBER> marshal ) | ||
{ | ||
super( fileSystem ); | ||
this.marshal = marshal; | ||
} | ||
|
||
@Override | ||
protected long getOrdinalOfLastRecord( File file ) throws IOException | ||
{ | ||
return readLastEntryFrom( fileSystem, file ).logIndex(); | ||
} | ||
|
||
public InMemoryGlobalSessionTrackerState<MEMBER> readLastEntryFrom( FileSystemAbstraction fileSystemAbstraction, File file ) throws IOException | ||
{ | ||
final ReadableChannel channel = new ReadAheadChannel<>( fileSystemAbstraction.open( file, "r" ) ); | ||
|
||
InMemoryGlobalSessionTrackerState<MEMBER> result = new InMemoryGlobalSessionTrackerState<>(); | ||
InMemoryGlobalSessionTrackerState<MEMBER> lastRead; | ||
|
||
while ( (lastRead = marshal.unmarshal( channel ) ) != null ) | ||
{ | ||
result = lastRead; | ||
} | ||
|
||
return result; | ||
} | ||
} |
Oops, something went wrong.