Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is the work on having an append only, rotateable raft log, based on PhysicalLogFile. Some supporting classes, including a Raft log entry cursor, are also introduced. PRL now has proper records that contain information about commit and truncation actions, besides the already existing append. Iteration over the log happens via a two layer cursor, one that iterates over records and another that builds up state and determines if entries are committed, truncated or appended Renames PhysicalLogFiles.hasAnyTransaction() to .hasAnyEntry() This is to remove notional dependencies of PLF to transactional concepts, since we want to use it elsewhere PRL can rotate and change versions via support from PhysicalLogFiles Log versions are maintained by scanning the filename suffixes present on disk, instead of having a dedicated file storage like tx logs Changes semantics of RaftEntryStore, cursors may be before requested index Previously there was an implicit assumption that cursors returned from RaftEntryStore would be positioned at the requested index. This is not true for the current implementation, so instead PhysicalRaftLog assumes that the cursor must be iterated until the desired index is reached. This also requires the cursor to return RaftEntryRecords instead of RaftLogEntries, so that it's possible to compare indexes.
- Loading branch information
1 parent
51d12d0
commit 3e08266
Showing
32 changed files
with
2,036 additions
and
19 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
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
51 changes: 51 additions & 0 deletions
51
...ore-edge/src/main/java/org/neo4j/coreedge/raft/log/FilenameBasedLogVersionRepository.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,51 @@ | ||
/* | ||
* 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.log; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
import org.neo4j.io.file.Files; | ||
import org.neo4j.io.fs.FileSystemAbstraction; | ||
import org.neo4j.kernel.impl.transaction.log.LogVersionRepository; | ||
import org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles; | ||
|
||
public class FilenameBasedLogVersionRepository implements LogVersionRepository | ||
{ | ||
private long version = 0; | ||
|
||
public FilenameBasedLogVersionRepository( PhysicalLogFiles logFiles) | ||
{ | ||
version = Math.max(logFiles.getHighestLogVersion(), 0); | ||
} | ||
|
||
|
||
@Override | ||
public long getCurrentLogVersion() | ||
{ | ||
return version; | ||
} | ||
|
||
@Override | ||
public long incrementAndGetVersion() throws IOException | ||
{ | ||
return ++version; | ||
} | ||
} |
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
105 changes: 105 additions & 0 deletions
105
enterprise/core-edge/src/main/java/org/neo4j/coreedge/raft/log/PhysicalRaftEntryStore.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,105 @@ | ||
/* | ||
* 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.log; | ||
|
||
import java.io.IOException; | ||
|
||
import org.neo4j.coreedge.raft.replication.ReplicatedContent; | ||
import org.neo4j.coreedge.raft.state.ChannelMarshal; | ||
import org.neo4j.cursor.IOCursor; | ||
import org.neo4j.kernel.impl.transaction.log.LogFile; | ||
import org.neo4j.kernel.impl.transaction.log.LogHeaderVisitor; | ||
import org.neo4j.kernel.impl.transaction.log.LogPosition; | ||
import org.neo4j.kernel.impl.transaction.log.ReadableLogChannel; | ||
|
||
public class PhysicalRaftEntryStore implements RaftEntryStore | ||
{ | ||
private final LogFile logFile; | ||
private final RaftLogMetadataCache metadataCache; | ||
private final ChannelMarshal<ReplicatedContent> marshal; | ||
|
||
public PhysicalRaftEntryStore( LogFile logFile, RaftLogMetadataCache metadataCache, | ||
ChannelMarshal<ReplicatedContent> marshal ) | ||
{ | ||
this.logFile = logFile; | ||
this.metadataCache = metadataCache; | ||
this.marshal = marshal; | ||
} | ||
|
||
@Override | ||
public IOCursor<RaftLogAppendRecord> getEntriesFrom( final long indexToStartFrom ) throws RaftStorageException | ||
{ | ||
// look up in position cache | ||
try | ||
{ | ||
RaftLogMetadataCache.RaftLogEntryMetadata metadata = metadataCache.getMetadata( indexToStartFrom ); | ||
LogPosition startPosition = null; | ||
if ( metadata != null ) | ||
{ | ||
startPosition = metadata.getStartPosition(); | ||
} | ||
else | ||
{ | ||
// ask LogFile about the version it may be in | ||
LogVersionLocator headerVisitor = new LogVersionLocator( indexToStartFrom ); | ||
logFile.accept( headerVisitor ); | ||
startPosition = headerVisitor.getLogPosition(); | ||
} | ||
if ( startPosition == null ) | ||
{ | ||
return IOCursor.getEmpty(); | ||
} | ||
ReadableLogChannel reader = logFile.getReader( startPosition ); | ||
|
||
return new PhysicalRaftLogEntryCursor( new RaftRecordCursor<>( reader, marshal ) ); | ||
} | ||
catch ( IOException e ) | ||
{ | ||
throw new RaftStorageException( e ); | ||
} | ||
} | ||
|
||
public static final class LogVersionLocator implements LogHeaderVisitor | ||
{ | ||
private final long logEntryIndex; | ||
private LogPosition foundPosition; | ||
|
||
public LogVersionLocator( long logEntryIndex ) | ||
{ | ||
this.logEntryIndex = logEntryIndex; | ||
} | ||
|
||
@Override | ||
public boolean visit( LogPosition position, long firstLogIndex, long lastLogIndex ) | ||
{ | ||
boolean foundIt = logEntryIndex >= firstLogIndex && logEntryIndex <= lastLogIndex; | ||
if ( foundIt ) | ||
{ | ||
foundPosition = position; | ||
} | ||
return !foundIt; // continue as long we don't find it | ||
} | ||
|
||
public LogPosition getLogPosition() throws RaftStorageException | ||
{ | ||
return foundPosition; | ||
} | ||
} | ||
} |
Oops, something went wrong.