Skip to content

Commit

Permalink
Moved Command.Version to o.n.storageengine.api.CommandVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
tinwelint committed Aug 10, 2018
1 parent ecab124 commit a68a97c
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 58 deletions.
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2002-2018 "Neo4j,"
* Neo4j Sweden AB [http://neo4j.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 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.storageengine.api;

/**
* Many commands have before/after versions of their records. In some scenarios there's a need
* to parameterize which of those to work with.
*/
public enum CommandVersion
{
/**
* The "before" version of a command's record. I.e. the record how it looked before changes took place.
*/
BEFORE,
/**
* The "after" version of a command's record. I.e. the record how it looks after changes took place.
*/
AFTER
}
Expand Up @@ -19,10 +19,8 @@
*/
package org.neo4j.storageengine.api;

import org.neo4j.kernel.impl.transaction.command.Command.Version;

import static org.neo4j.kernel.impl.transaction.command.Command.Version.AFTER;
import static org.neo4j.kernel.impl.transaction.command.Command.Version.BEFORE;
import static org.neo4j.storageengine.api.CommandVersion.AFTER;
import static org.neo4j.storageengine.api.CommandVersion.BEFORE;

/**
* Mode of {@link StorageEngine#apply(CommandsToApply, TransactionApplicationMode) applying transactions}.
Expand Down Expand Up @@ -88,10 +86,10 @@ public enum TransactionApplicationMode
private final boolean needsCacheInvalidation;
private final boolean needsIdempotencyChecks;
private final boolean indexesAndCounts;
private final Version version;
private final CommandVersion version;

TransactionApplicationMode( boolean needsHighIdTracking, boolean needsCacheInvalidation,
boolean ensureIdempotency, boolean indexesAndCounts, Version version )
boolean ensureIdempotency, boolean indexesAndCounts, CommandVersion version )
{
this.needsHighIdTracking = needsHighIdTracking;
this.needsCacheInvalidation = needsCacheInvalidation;
Expand Down Expand Up @@ -135,7 +133,7 @@ public boolean needsAuxiliaryStores()
/**
* @return which version of commands to apply, where some commands have before/after versions.
*/
public Version version()
public CommandVersion version()
{
return version;
}
Expand Down
Expand Up @@ -91,44 +91,6 @@ public static Mode fromRecordState( AbstractBaseRecord record )
}
}

/**
* Many commands have before/after versions of their records. In some scenarios there's a need
* to parameterize which of those to work with.
*/
public enum Version
{
/**
* The "before" version of a command's record. I.e. the record how it looked before changes took place.
*/
BEFORE
{
@Override
<RECORD extends AbstractBaseRecord> RECORD select( BaseCommand<RECORD> command )
{
return command.getBefore();
}
},
/**
* The "after" version of a command's record. I.e. the record how it looks after changes took place.
*/
AFTER
{
@Override
<RECORD extends AbstractBaseRecord> RECORD select( BaseCommand<RECORD> command )
{
return command.getAfter();
}
};

/**
* Selects one of the versions of a {@link BaseCommand}.
*
* @param command command to select a version from.
* @return the specific record version in this command.
*/
abstract <RECORD extends AbstractBaseRecord> RECORD select( BaseCommand<RECORD> command );
}

protected final void setup( long key, Mode mode )
{
this.mode = mode;
Expand Down
Expand Up @@ -19,15 +19,13 @@
*/
package org.neo4j.kernel.impl.transaction.command;

import java.io.IOException;

import org.neo4j.kernel.impl.api.BatchTransactionApplier;
import org.neo4j.kernel.impl.api.TransactionApplier;
import org.neo4j.kernel.impl.core.CacheAccessBackDoor;
import org.neo4j.kernel.impl.locking.LockGroup;
import org.neo4j.kernel.impl.locking.LockService;
import org.neo4j.kernel.impl.store.NeoStores;
import org.neo4j.kernel.impl.transaction.command.Command.Version;
import org.neo4j.storageengine.api.CommandVersion;
import org.neo4j.storageengine.api.CommandsToApply;

/**
Expand All @@ -38,18 +36,18 @@
*/
public class NeoStoreBatchTransactionApplier extends BatchTransactionApplier.Adapter
{
private final Version version;
private final CommandVersion version;
private final NeoStores neoStores;
// Ideally we don't want any cache access in here, but it is how it is. At least we try to minimize use of it
private final CacheAccessBackDoor cacheAccess;
private final LockService lockService;

public NeoStoreBatchTransactionApplier( NeoStores store, CacheAccessBackDoor cacheAccess, LockService lockService )
{
this( Version.AFTER, store, cacheAccess, lockService );
this( CommandVersion.AFTER, store, cacheAccess, lockService );
}

public NeoStoreBatchTransactionApplier( Version version, NeoStores store, CacheAccessBackDoor cacheAccess, LockService lockService )
public NeoStoreBatchTransactionApplier( CommandVersion version, NeoStores store, CacheAccessBackDoor cacheAccess, LockService lockService )
{
this.version = version;
this.neoStores = store;
Expand Down
Expand Up @@ -19,8 +19,6 @@
*/
package org.neo4j.kernel.impl.transaction.command;

import java.io.IOException;

import org.neo4j.kernel.impl.api.TransactionApplier;
import org.neo4j.kernel.impl.core.CacheAccessBackDoor;
import org.neo4j.kernel.impl.locking.LockGroup;
Expand All @@ -32,7 +30,7 @@
import org.neo4j.kernel.impl.store.record.ConstraintRule;
import org.neo4j.kernel.impl.store.record.DynamicRecord;
import org.neo4j.kernel.impl.transaction.command.Command.BaseCommand;
import org.neo4j.kernel.impl.transaction.command.Command.Version;
import org.neo4j.storageengine.api.CommandVersion;

/**
* Visits commands targeted towards the {@link NeoStores} and update corresponding stores.
Expand All @@ -44,14 +42,14 @@
*/
public class NeoStoreTransactionApplier extends TransactionApplier.Adapter
{
private final Version version;
private final CommandVersion version;
private final LockGroup lockGroup;
private final long transactionId;
private final NeoStores neoStores;
private final CacheAccessBackDoor cacheAccess;
private final LockService lockService;

public NeoStoreTransactionApplier( Version version, NeoStores neoStores, CacheAccessBackDoor cacheAccess, LockService lockService,
public NeoStoreTransactionApplier( CommandVersion version, NeoStores neoStores, CacheAccessBackDoor cacheAccess, LockService lockService,
long transactionId, LockGroup lockGroup )
{
this.version = version;
Expand Down Expand Up @@ -181,12 +179,25 @@ public boolean visitSchemaRuleCommand( Command.SchemaRuleCommand command )
@Override
public boolean visitNeoStoreCommand( Command.NeoStoreCommand command )
{
neoStores.getMetaDataStore().setGraphNextProp( version.select( command ).getNextProp() );
neoStores.getMetaDataStore().setGraphNextProp( selectRecordByCommandVersion( command ).getNextProp() );
return false;
}

private <RECORD extends AbstractBaseRecord> void updateStore( RecordStore<RECORD> store, BaseCommand<RECORD> command )
{
store.updateRecord( version.select( command ) );
store.updateRecord( selectRecordByCommandVersion( command ) );
}

private <RECORD extends AbstractBaseRecord> RECORD selectRecordByCommandVersion( BaseCommand<RECORD> command )
{
switch ( version )
{
case BEFORE:
return command.getBefore();
case AFTER:
return command.getAfter();
default:
throw new IllegalArgumentException( "Unexpected command version " + version );
}
}
}

0 comments on commit a68a97c

Please sign in to comment.