Skip to content

Commit

Permalink
Introduces state persistence for GlobalSessionTracker and LockTokenState
Browse files Browse the repository at this point in the history
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
digitalstain committed Jan 21, 2016
1 parent eda2044 commit 42ee803
Show file tree
Hide file tree
Showing 27 changed files with 1,228 additions and 328 deletions.
Expand Up @@ -21,16 +21,14 @@

import java.util.UUID;

import org.neo4j.coreedge.server.CoreMember;

import static java.lang.String.format;

public class GlobalSession
public class GlobalSession<MEMBER>
{
private final UUID sessionId;
private final CoreMember owner;
private final MEMBER owner;

public GlobalSession( UUID sessionId, CoreMember owner )
public GlobalSession( UUID sessionId, MEMBER owner )
{
this.sessionId = sessionId;
this.owner = owner;
Expand All @@ -41,7 +39,7 @@ public UUID sessionId()
return sessionId;
}

public CoreMember owner()
public MEMBER owner()
{
return owner;
}
Expand Down

This file was deleted.

@@ -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 );
}
@@ -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;
}
}

0 comments on commit 42ee803

Please sign in to comment.