Skip to content

Commit

Permalink
Uses term 'close' instead of mixed apply/close and makes TxStateVisit…
Browse files Browse the repository at this point in the history
…or an AutoCloseable since less confusing than having explicit done() method
  • Loading branch information
tinwelint committed Dec 1, 2015
1 parent 40e7c5e commit 164cf7e
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 32 deletions.
Expand Up @@ -36,7 +36,7 @@
/** /**
* A visitor for visiting the changes that have been made in a transaction. * A visitor for visiting the changes that have been made in a transaction.
*/ */
public interface TxStateVisitor public interface TxStateVisitor extends AutoCloseable
{ {
void visitCreatedNode( long id ); void visitCreatedNode( long id );


Expand Down Expand Up @@ -94,10 +94,8 @@ void visitAddedRelationshipPropertyExistenceConstraint( RelationshipPropertyExis


void visitDroppedProcedure( ProcedureDescriptor procedureDescriptor ); void visitDroppedProcedure( ProcedureDescriptor procedureDescriptor );


/** @Override
* Must be called Called after all visitor methods, i.e. all changes have been visited. void close();
*/
void done();


class Adapter implements TxStateVisitor class Adapter implements TxStateVisitor
{ {
Expand Down Expand Up @@ -233,7 +231,7 @@ public void visitDroppedProcedure( ProcedureDescriptor procedureDescriptor )
} }


@Override @Override
public void done() public void close()
{ {
} }
} }
Expand Down Expand Up @@ -406,9 +404,9 @@ public void visitDroppedProcedure( ProcedureDescriptor procedureDescriptor )
} }


@Override @Override
public void done() public void close()
{ {
actual.done(); actual.close();
} }
} }
} }
Expand Up @@ -148,7 +148,7 @@ private void close( TransactionToApply batch )
{ {
if ( batch.commitment().markedAsCommitted() ) if ( batch.commitment().markedAsCommitted() )
{ {
batch.commitment().publishAsApplied(); batch.commitment().publishAsClosed();
} }
batch = batch.next(); batch = batch.next();
} }
Expand Down
Expand Up @@ -104,7 +104,7 @@ Collection<Command> createCommands(
/** /**
* Apply a batch of transactions to this storage. Transactions are applied to storage after being committed, * Apply a batch of transactions to this storage. Transactions are applied to storage after being committed,
* i.e. appended to a log by {@link TransactionAppender}. Implementations should NOT * i.e. appended to a log by {@link TransactionAppender}. Implementations should NOT
* {@link Commitment#publishAsApplied() mark transactions as applied}, instead caller is expected to do that. * {@link Commitment#publishAsClosed() mark transactions as applied}, instead caller is expected to do that.
* Caller is typically {@link TransactionCommitProcess}. * Caller is typically {@link TransactionCommitProcess}.
* *
* @param batch batch of transactions to apply to storage. * @param batch batch of transactions to apply to storage.
Expand Down
Expand Up @@ -230,6 +230,7 @@ public StoreReadLayer storeReadLayer()
return storeLayer; return storeLayer;
} }


@SuppressWarnings( "resource" )
@Override @Override
public Collection<Command> createCommands( public Collection<Command> createCommands(
TransactionState txState, TransactionState txState,
Expand Down Expand Up @@ -267,8 +268,10 @@ public Collection<Command> createCommands(
txStateVisitor ); txStateVisitor );
txStateVisitor = new TransactionCountingStateVisitor( txStateVisitor = new TransactionCountingStateVisitor(
txStateVisitor, storeLayer, txState, countsRecordState ); txStateVisitor, storeLayer, txState, countsRecordState );
txState.accept( txStateVisitor ); try ( TxStateVisitor visitor = txStateVisitor )
txStateVisitor.done(); {
txState.accept( txStateVisitor );
}


// Convert record state into commands // Convert record state into commands
recordState.extractCommands( commands ); recordState.extractCommands( commands );
Expand Down
Expand Up @@ -72,7 +72,7 @@ public TransactionToRecordStateVisitor( TransactionRecordState recordState, Runn
} }


@Override @Override
public void done() public void close()
{ {
try try
{ {
Expand Down
Expand Up @@ -19,14 +19,15 @@
*/ */
package org.neo4j.kernel.impl.transaction.log; package org.neo4j.kernel.impl.transaction.log;


import org.neo4j.kernel.impl.api.TransactionCommitProcess;
import org.neo4j.kernel.impl.api.TransactionToApply;
import org.neo4j.kernel.impl.transaction.tracing.LogAppendEvent;


/** /**
* A way to mark a transaction as committed after * Represents a commitment that invoking {@link TransactionAppender#append(TransactionToApply, LogAppendEvent)}
* {@link TransactionAppender#append(org.neo4j.kernel.impl.transaction.TransactionRepresentation, long) appended} * means. As a transaction is carried through the {@link TransactionCommitProcess} this commitment is updated
* and manually {@link TransactionAppender#force() forced} and later closed after * when {@link #publishAsCommitted() committed} (which happens when appending to log), but also
* {@link org.neo4j.kernel.impl.api.TransactionRepresentationStoreApplier#apply( * when {@link #publishAsClosed() closing}.
* org.neo4j.kernel.impl.transaction.TransactionRepresentation, org.neo4j.kernel.impl.api.index.ValidatedIndexUpdates,
* org.neo4j.kernel.impl.locking.LockGroup, long, org.neo4j.kernel.impl.api.TransactionApplicationMode)} .
*/ */
public interface Commitment public interface Commitment
{ {
Expand All @@ -38,7 +39,7 @@ public void publishAsCommitted()
} }


@Override @Override
public void publishAsApplied() public void publishAsClosed()
{ {
} }


Expand All @@ -56,20 +57,22 @@ public boolean hasLegacyIndexChanges()
}; };


/** /**
* <p> * Marks the transaction as committed and makes this fact public.
* Marks the transaction as committed and makes this fact public.
* </p>
*/ */
void publishAsCommitted(); void publishAsCommitted();


/** /**
* <p> * Marks the transaction as closed and makes this fact public.
* Marks the transaction as closed and makes this fact public.
* </p>
*/ */
void publishAsApplied(); void publishAsClosed();


/**
* @return whether or not {@link #publishAsCommitted()} have been called.
*/
boolean markedAsCommitted(); boolean markedAsCommitted();


/**
* @return whether or not this transaction contains legacy index changes.
*/
boolean hasLegacyIndexChanges(); boolean hasLegacyIndexChanges();
} }
Expand Up @@ -39,15 +39,15 @@ public interface TransactionAppender
* *
* Any failure happening inside this method will cause a {@link KernelHealth#panic(Throwable) kernel panic}. * Any failure happening inside this method will cause a {@link KernelHealth#panic(Throwable) kernel panic}.
* Callers must make sure that successfully appended * Callers must make sure that successfully appended
* transactions exiting this method are {@link Commitment#publishAsApplied()}}. * transactions exiting this method are {@link Commitment#publishAsClosed()}}.
* *
* @param batch transactions to append to the log. These transaction instances provide both input arguments * @param batch transactions to append to the log. These transaction instances provide both input arguments
* as well as a place to provide output data, namely {@link TransactionToApply#commitment()} and * as well as a place to provide output data, namely {@link TransactionToApply#commitment()} and
* {@link TransactionToApply#transactionId()}. * {@link TransactionToApply#transactionId()}.
* @param logAppendEvent A trace event for the given log append operation. * @param logAppendEvent A trace event for the given log append operation.
* @return last committed transaction in this batch. The appended (i.e. committed) transactions * @return last committed transaction in this batch. The appended (i.e. committed) transactions
* will have had their {@link TransactionToApply#commitment()} available and caller is expected to * will have had their {@link TransactionToApply#commitment()} available and caller is expected to
* {@link Commitment#publishAsApplied() mark them as applied} after they have been applied to storage. * {@link Commitment#publishAsClosed() mark them as applied} after they have been applied to storage.
* Note that {@link Commitment commitments} must be {@link Commitment#publishAsCommitted() marked as committed} * Note that {@link Commitment commitments} must be {@link Commitment#publishAsCommitted() marked as committed}
* by this method. * by this method.
* @throws IOException if there was a problem appending the transaction. See method javadoc body for * @throws IOException if there was a problem appending the transaction. See method javadoc body for
Expand Down
Expand Up @@ -46,7 +46,7 @@ public void publishAsCommitted()
} }


@Override @Override
public void publishAsApplied() public void publishAsClosed()
{ {
transactionIdStore.transactionClosed( transactionId, transactionIdStore.transactionClosed( transactionId,
logPosition.getLogVersion(), logPosition.getByteOffset() ); logPosition.getLogVersion(), logPosition.getByteOffset() );
Expand Down
Expand Up @@ -73,12 +73,16 @@ public interface TransactionIdStore
/** /**
* Returns transaction information about the highest committed transaction, i.e. * Returns transaction information about the highest committed transaction, i.e.
* transaction id as well as checksum. * transaction id as well as checksum.
*
* @return {@link TransactionId} describing the last (i.e. highest) committed transaction.
*/ */
TransactionId getLastCommittedTransaction(); TransactionId getLastCommittedTransaction();


/** /**
* Returns transaction information about transaction where the last upgrade was performed, i.e. * Returns transaction information about transaction where the last upgrade was performed, i.e.
* transaction id as well as checksum. * transaction id as well as checksum.
*
* @return {@link TransactionId} describing the most recent upgrade transaction.
*/ */
TransactionId getUpgradeTransaction(); TransactionId getUpgradeTransaction();


Expand All @@ -90,6 +94,13 @@ public interface TransactionIdStore
/** /**
* Returns transaction information about the last committed transaction, i.e. * Returns transaction information about the last committed transaction, i.e.
* transaction id as well as the log position following the commit entry in the transaction log. * transaction id as well as the log position following the commit entry in the transaction log.
*
* @return transaction information about the last closed (highest gap-free) transaction.
* <pre>
* [0]: transaction id
* [1]: log version
* [2]: byte offset into that log version
* </pre>
*/ */
long[] getLastClosedTransaction(); long[] getLastClosedTransaction();


Expand Down
Expand Up @@ -46,7 +46,7 @@ public void publishAsCommitted()
} }


@Override @Override
public void publishAsApplied() public void publishAsClosed()
{ {
transactionIdStore.transactionClosed( id, 1, 2 ); transactionIdStore.transactionClosed( id, 1, 2 );
} }
Expand Down
Expand Up @@ -36,7 +36,7 @@ public boolean markedAsCommitted()
} }


@Override @Override
public void publishAsApplied() public void publishAsClosed()
{ {
} }


Expand Down

0 comments on commit 164cf7e

Please sign in to comment.