Skip to content

Commit

Permalink
core-edge: rename marshal
Browse files Browse the repository at this point in the history
  • Loading branch information
martinfurmanski committed Aug 18, 2016
1 parent 2809ea7 commit 1d922f3
Show file tree
Hide file tree
Showing 18 changed files with 35 additions and 36 deletions.
Expand Up @@ -62,7 +62,7 @@ public ReplicationModule( MemberId myself, PlatformModule platformModule, Config
try
{
sessionTrackerStorage = life.add( new DurableStateStorage<>( fileSystem, clusterStateDirectory,
SESSION_TRACKER_NAME, new GlobalSessionTrackerState.Marshal( new MemberId.MemberIdMarshal() ),
SESSION_TRACKER_NAME, new GlobalSessionTrackerState.Marshal( new MemberId.Marshal() ),
config.get( CoreEdgeClusterSettings.global_session_tracker_state_size ), logProvider ) );
}
catch ( IOException e )
Expand Down
Expand Up @@ -44,7 +44,6 @@
import org.neo4j.coreedge.discovery.procedures.CoreRoleProcedure;
import org.neo4j.coreedge.discovery.procedures.DiscoverEndpointAcquisitionServersProcedure;
import org.neo4j.coreedge.identity.MemberId;
import org.neo4j.coreedge.identity.MemberId.MemberIdMarshal;
import org.neo4j.coreedge.logging.BetterMessageLogger;
import org.neo4j.coreedge.logging.MessageLogger;
import org.neo4j.coreedge.logging.NullMessageLogger;
Expand Down Expand Up @@ -148,7 +147,7 @@ public void registerProcedures( Procedures procedures )

life.add( localDatabase );

MemberIdStorage memberIdStorage = new MemberIdStorage( fileSystem, clusterStateDirectory, CORE_MEMBER_ID_NAME, new MemberIdMarshal(), logProvider );
MemberIdStorage memberIdStorage = new MemberIdStorage( fileSystem, clusterStateDirectory, CORE_MEMBER_ID_NAME, new MemberId.Marshal(), logProvider );
MemberId myself;
try
{
Expand Down
Expand Up @@ -99,7 +99,7 @@ public ConsensusModule( MemberId myself, final PlatformModule platformModule, Ou

voteState = life.add(
new DurableStateStorage<>( fileSystem, clusterStateDirectory, RAFT_VOTE_NAME,
new VoteState.Marshal( new MemberId.MemberIdMarshal() ),
new VoteState.Marshal( new MemberId.Marshal() ),
config.get( CoreEdgeClusterSettings.vote_state_size ), logProvider ) );

raftMembershipStorage = life.add(
Expand Down
Expand Up @@ -50,7 +50,7 @@ public static void marshal( MemberIdSet memberSet, WritableChannel channel ) thr
Set<MemberId> members = memberSet.getMembers();
channel.putInt( members.size() );

MemberId.MemberIdMarshal memberIdMarshal = new MemberId.MemberIdMarshal();
MemberId.Marshal memberIdMarshal = new MemberId.Marshal();

for ( MemberId member : members )
{
Expand All @@ -63,7 +63,7 @@ public static MemberIdSet unmarshal( ReadableChannel channel ) throws IOExceptio
HashSet<MemberId> members = new HashSet<>();
int memberCount = channel.getInt();

MemberId.MemberIdMarshal memberIdMarshal = new MemberId.MemberIdMarshal();
MemberId.Marshal memberIdMarshal = new MemberId.Marshal();

for ( int i = 0; i < memberCount; i++ )
{
Expand Down
Expand Up @@ -83,7 +83,7 @@ public String toString()

static class Marshal extends SafeStateMarshal<MembershipEntry>
{
MemberId.MemberIdMarshal memberMarshal = new MemberId.MemberIdMarshal();
MemberId.Marshal memberMarshal = new MemberId.Marshal();

@Override
public MembershipEntry startState()
Expand Down
Expand Up @@ -65,7 +65,7 @@ public void serialize( WritableChannel channel ) throws IOException
{
channel.putLong( globalSession().sessionId().getMostSignificantBits() );
channel.putLong( globalSession().sessionId().getLeastSignificantBits() );
new MemberId.MemberIdMarshal().marshal( globalSession().owner(), channel );
new MemberId.Marshal().marshal( globalSession().owner(), channel );

channel.putLong( operationId.localSessionId() );
channel.putLong( operationId.sequenceNumber() );
Expand All @@ -77,7 +77,7 @@ public static DistributedOperation deserialize( ReadableChannel channel ) throws
{
long mostSigBits = channel.getLong();
long leastSigBits = channel.getLong();
MemberId owner = new MemberId.MemberIdMarshal().unmarshal( channel );
MemberId owner = new MemberId.Marshal().unmarshal( channel );
GlobalSession globalSession = new GlobalSession( new UUID( mostSigBits, leastSigBits ), owner );

long localSessionId = channel.getLong();
Expand Down
Expand Up @@ -33,7 +33,7 @@
import org.neo4j.coreedge.core.state.storage.MemberIdStorage;
import org.neo4j.coreedge.core.state.storage.StateMarshal;
import org.neo4j.coreedge.identity.MemberId;
import org.neo4j.coreedge.identity.MemberId.MemberIdMarshal;
import org.neo4j.coreedge.identity.MemberId.Marshal;
import org.neo4j.io.fs.DefaultFileSystemAbstraction;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.kernel.lifecycle.Lifespan;
Expand Down Expand Up @@ -85,22 +85,22 @@ public static void main( String[] args ) throws IOException
void dump() throws IOException
{
MemberIdStorage memberIdStorage = new MemberIdStorage( fs, clusterStateDirectory, CORE_MEMBER_ID_NAME,
new MemberIdMarshal(), NullLogProvider.getInstance() );
new Marshal(), NullLogProvider.getInstance() );
if ( memberIdStorage.exists() )
{
MemberId memberId = memberIdStorage.readState();
out.println( CORE_MEMBER_ID_NAME + ": " + memberId );
}

dumpState( LAST_FLUSHED_NAME, new LongIndexMarshal() );
dumpState( LOCK_TOKEN_NAME, new ReplicatedLockTokenState.Marshal( new MemberIdMarshal() ) );
dumpState( LOCK_TOKEN_NAME, new ReplicatedLockTokenState.Marshal( new Marshal() ) );
dumpState( ID_ALLOCATION_NAME, new IdAllocationState.Marshal() );
dumpState( SESSION_TRACKER_NAME, new GlobalSessionTrackerState.Marshal( new MemberIdMarshal() ) );
dumpState( SESSION_TRACKER_NAME, new GlobalSessionTrackerState.Marshal( new Marshal() ) );

/* raft state */
dumpState( RAFT_MEMBERSHIP_NAME, new RaftMembershipState.Marshal() );
dumpState( RAFT_TERM_NAME, new TermState.Marshal() );
dumpState( RAFT_VOTE_NAME, new VoteState.Marshal( new MemberIdMarshal() ) );
dumpState( RAFT_VOTE_NAME, new VoteState.Marshal( new Marshal() ) );
}

private void dumpState( String name, StateMarshal<?> marshal ) throws IOException
Expand Down
Expand Up @@ -95,7 +95,7 @@ public CoreStateMachinesModule( MemberId myself, PlatformModule platformModule,
{
lockTokenState = life.add(
new DurableStateStorage<>( fileSystem, clusterStateDirectory, LOCK_TOKEN_NAME,
new ReplicatedLockTokenState.Marshal( new MemberId.MemberIdMarshal() ),
new ReplicatedLockTokenState.Marshal( new MemberId.Marshal() ),
config.get( CoreEdgeClusterSettings.replicated_lock_token_state_size ), logProvider ) );

idAllocationState = life.add(
Expand Down
Expand Up @@ -32,15 +32,15 @@ public class ReplicatedIdAllocationRequestSerializer
public static void marshal( ReplicatedIdAllocationRequest idRangeRequest, WritableChannel channel )
throws IOException
{
new MemberId.MemberIdMarshal().marshal( idRangeRequest.owner(), channel );
new MemberId.Marshal().marshal( idRangeRequest.owner(), channel );
channel.putInt( idRangeRequest.idType().ordinal() );
channel.putLong( idRangeRequest.idRangeStart() );
channel.putInt( idRangeRequest.idRangeLength() );
}

public static ReplicatedIdAllocationRequest unmarshal( ReadableChannel channel ) throws IOException, EndOfStreamException
{
MemberId owner = new MemberId.MemberIdMarshal().unmarshal( channel );
MemberId owner = new MemberId.Marshal().unmarshal( channel );
IdType idType = IdType.values()[ channel.getInt() ];
long idRangeStart = channel.getLong();
int idRangeLength = channel.getInt();
Expand Down
Expand Up @@ -32,13 +32,13 @@ public static void marshal( ReplicatedLockTokenRequest tokenRequest, WritableCha
throws IOException
{
channel.putInt( tokenRequest.id() );
new MemberId.MemberIdMarshal().marshal( tokenRequest.owner(), channel );
new MemberId.Marshal().marshal( tokenRequest.owner(), channel );
}

public static ReplicatedLockTokenRequest unmarshal( ReadableChannel channel ) throws IOException, EndOfStreamException
{
int candidateId = channel.getInt();
MemberId owner = new MemberId.MemberIdMarshal().unmarshal( channel );
MemberId owner = new MemberId.Marshal().unmarshal( channel );

return new ReplicatedLockTokenRequest( owner, candidateId );
}
Expand Down
Expand Up @@ -27,8 +27,8 @@

public enum CoreStateType
{
LOCK_TOKEN( new ReplicatedLockTokenState.Marshal( new MemberId.MemberIdMarshal() ) ),
SESSION_TRACKER( new GlobalSessionTrackerState.Marshal( new MemberId.MemberIdMarshal() ) ),
LOCK_TOKEN( new ReplicatedLockTokenState.Marshal( new MemberId.Marshal() ) ),
SESSION_TRACKER( new GlobalSessionTrackerState.Marshal( new MemberId.Marshal() ) ),
ID_ALLOCATION( new IdAllocationState.Marshal() );

public final StateMarshal marshal;
Expand Down
Expand Up @@ -36,12 +36,12 @@
public class MemberIdStorage
{
private final FileSystemAbstraction fileSystem;
private final MemberId.MemberIdMarshal marshal;
private final MemberId.Marshal marshal;
private final File file;
private Log log;

public MemberIdStorage( FileSystemAbstraction fileSystem, File directory, String name,
MemberId.MemberIdMarshal marshal, LogProvider logProvider )
MemberId.Marshal marshal, LogProvider logProvider )
{
this.fileSystem = fileSystem;
this.log = logProvider.getLog( getClass() );
Expand Down
Expand Up @@ -145,7 +145,7 @@ else if ( messageType.equals( LOG_COMPACTION_INFO ) )

private MemberId retrieveMember( ReadableChannel buffer ) throws IOException, EndOfStreamException
{
MemberId.MemberIdMarshal memberIdMarshal = new MemberId.MemberIdMarshal();
MemberId.Marshal memberIdMarshal = new MemberId.Marshal();
return memberIdMarshal.unmarshal( buffer );
}
}
Expand Up @@ -48,7 +48,7 @@ protected synchronized void encode( ChannelHandlerContext ctx,
{
RaftMessages.RaftMessage message = decoratedMessage.message();
StoreId storeId = decoratedMessage.storeId();
MemberId.MemberIdMarshal memberMarshal = new MemberId.MemberIdMarshal();
MemberId.Marshal memberMarshal = new MemberId.Marshal();

NetworkFlushableByteBuf channel = new NetworkFlushableByteBuf( ctx.alloc().buffer() );
channel.put( message.version() );
Expand Down
Expand Up @@ -39,7 +39,7 @@ public class MemberIdMarshalTest
public void shouldSerializeAndDeserialize() throws Exception
{
// given
MemberId.MemberIdMarshal marshal = new MemberId.MemberIdMarshal();
MemberId.Marshal marshal = new MemberId.Marshal();

final MemberId member = new MemberId( UUID.randomUUID() );

Expand All @@ -57,7 +57,7 @@ public void shouldThrowExceptionForHalfWrittenInstance() throws Exception
{
// given
// a CoreMember and a ByteBuffer to write it to
MemberId.MemberIdMarshal marshal = new MemberId.MemberIdMarshal();
MemberId.Marshal marshal = new MemberId.Marshal();
final MemberId aRealMember = new MemberId( UUID.randomUUID() );

ByteBuf buffer = Unpooled.buffer( 1000 );
Expand Down
Expand Up @@ -75,18 +75,18 @@ public void shouldDumpClusterState() throws Exception

private void createStates() throws IOException
{
MemberIdStorage memberIdStorage = new MemberIdStorage( fsa.get(), clusterStateDirectory, CORE_MEMBER_ID_NAME, new MemberId.MemberIdMarshal(), NullLogProvider.getInstance() );
MemberIdStorage memberIdStorage = new MemberIdStorage( fsa.get(), clusterStateDirectory, CORE_MEMBER_ID_NAME, new MemberId.Marshal(), NullLogProvider.getInstance() );
memberIdStorage.readState();

createDurableState( LAST_FLUSHED_NAME, new LongIndexMarshal() );
createDurableState( LOCK_TOKEN_NAME, new ReplicatedLockTokenState.Marshal( new MemberId.MemberIdMarshal() ) );
createDurableState( LOCK_TOKEN_NAME, new ReplicatedLockTokenState.Marshal( new MemberId.Marshal() ) );
createDurableState( ID_ALLOCATION_NAME, new IdAllocationState.Marshal() );
createDurableState( SESSION_TRACKER_NAME, new GlobalSessionTrackerState.Marshal( new MemberId.MemberIdMarshal() ) );
createDurableState( SESSION_TRACKER_NAME, new GlobalSessionTrackerState.Marshal( new MemberId.Marshal() ) );

/* raft state */
createDurableState( RAFT_MEMBERSHIP_NAME, new RaftMembershipState.Marshal() );
createDurableState( RAFT_TERM_NAME, new TermState.Marshal() );
createDurableState( RAFT_VOTE_NAME, new VoteState.Marshal( new MemberId.MemberIdMarshal() ) );
createDurableState( RAFT_VOTE_NAME, new VoteState.Marshal( new MemberId.Marshal() ) );
}

private <T> void createDurableState( String name, StateMarshal<T> marshal ) throws IOException
Expand Down
Expand Up @@ -185,7 +185,7 @@ public void shouldPersistAndRecoverState() throws Exception
fsa.mkdir( testDir.directory() );

StateMarshal<ReplicatedLockTokenState> marshal =
new ReplicatedLockTokenState.Marshal( new MemberId.MemberIdMarshal() );
new ReplicatedLockTokenState.Marshal( new MemberId.Marshal() );

MemberId memberA = member( 0 );
MemberId memberB = member( 1 );
Expand Down Expand Up @@ -227,7 +227,7 @@ public void shouldBeIdempotent() throws Exception
fsa.mkdir( testDir.directory() );

StateMarshal<ReplicatedLockTokenState> marshal =
new ReplicatedLockTokenState.Marshal( new MemberId.MemberIdMarshal() );
new ReplicatedLockTokenState.Marshal( new MemberId.Marshal() );

DurableStateStorage<ReplicatedLockTokenState> storage = new DurableStateStorage<>( fsa, testDir.directory(),
"state", marshal, 100, NullLogProvider.getInstance() );
Expand Down
Expand Up @@ -39,8 +39,8 @@ public class MemberIdStorageTest
public void shouldInitializeWithUniqueMemberId() throws Exception
{
// given
MemberIdStorage storageA = new MemberIdStorage( fsa.get(), new File( "state-dir" ), "member-id-a", new MemberId.MemberIdMarshal(), NullLogProvider.getInstance() );
MemberIdStorage storageB = new MemberIdStorage( fsa.get(), new File( "state-dir" ), "member-id-b", new MemberId.MemberIdMarshal(), NullLogProvider.getInstance() );
MemberIdStorage storageA = new MemberIdStorage( fsa.get(), new File( "state-dir" ), "member-id-a", new MemberId.Marshal(), NullLogProvider.getInstance() );
MemberIdStorage storageB = new MemberIdStorage( fsa.get(), new File( "state-dir" ), "member-id-b", new MemberId.Marshal(), NullLogProvider.getInstance() );

// when
MemberId idA = storageA.readState();
Expand All @@ -55,7 +55,7 @@ public void shouldInitializeWithUniqueMemberId() throws Exception
public void shouldReadInitializedStateOnSubsequentInvocation() throws Exception
{
// given
MemberIdStorage storage = new MemberIdStorage( fsa.get(), new File( "state-dir" ), "member-id", new MemberId.MemberIdMarshal(), NullLogProvider.getInstance() );
MemberIdStorage storage = new MemberIdStorage( fsa.get(), new File( "state-dir" ), "member-id", new MemberId.Marshal(), NullLogProvider.getInstance() );
MemberId memberIdA = storage.readState();

// when
Expand Down

0 comments on commit 1d922f3

Please sign in to comment.