diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/storageengine/impl/recordstorage/RecordStorageEngine.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/storageengine/impl/recordstorage/RecordStorageEngine.java index dfce9def4cd88..dff14f8ca2e78 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/storageengine/impl/recordstorage/RecordStorageEngine.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/storageengine/impl/recordstorage/RecordStorageEngine.java @@ -28,6 +28,7 @@ import org.neo4j.concurrent.WorkSync; import org.neo4j.graphdb.config.Setting; +import org.neo4j.graphdb.factory.GraphDatabaseSettings; import org.neo4j.io.fs.FileSystemAbstraction; import org.neo4j.io.pagecache.PageCache; import org.neo4j.kernel.impl.store.id.IdGeneratorFactory; @@ -80,8 +81,14 @@ import org.neo4j.kernel.impl.transaction.state.IntegrityValidator; import org.neo4j.kernel.impl.transaction.state.Loaders; import org.neo4j.kernel.impl.transaction.state.NeoStoreIndexStoreView; -import org.neo4j.kernel.impl.transaction.state.NeoStoreTransactionContext; +import org.neo4j.kernel.impl.transaction.state.PropertyCreator; +import org.neo4j.kernel.impl.transaction.state.PropertyDeleter; import org.neo4j.kernel.impl.transaction.state.PropertyLoader; +import org.neo4j.kernel.impl.transaction.state.PropertyTraverser; +import org.neo4j.kernel.impl.transaction.state.RecordChangeSet; +import org.neo4j.kernel.impl.transaction.state.RelationshipCreator; +import org.neo4j.kernel.impl.transaction.state.RelationshipDeleter; +import org.neo4j.kernel.impl.transaction.state.RelationshipGroupGetter; import org.neo4j.kernel.impl.transaction.state.TransactionRecordState; import org.neo4j.kernel.impl.util.DependencySatisfier; import org.neo4j.kernel.impl.util.IdOrderingQueue; @@ -146,6 +153,10 @@ public class RecordStorageEngine implements StorageEngine, Lifecycle // Immutable state for creating/applying commands private final Loaders loaders; + private final RelationshipCreator relationshipCreator; + private final RelationshipDeleter relationshipDeleter; + private final PropertyCreator propertyCreator; + private final PropertyDeleter propertyDeleter; public RecordStorageEngine( File storeDir, @@ -216,6 +227,14 @@ public RecordStorageEngine( // Immutable state for creating/applying commands loaders = new Loaders( neoStores ); + RelationshipGroupGetter relationshipGroupGetter = + new RelationshipGroupGetter( neoStores.getRelationshipGroupStore() ); + relationshipCreator = new RelationshipCreator( relationshipGroupGetter, + config.get( GraphDatabaseSettings.dense_node_threshold ) ); + PropertyTraverser propertyTraverser = new PropertyTraverser(); + propertyDeleter = new PropertyDeleter( neoStores.getPropertyStore(), propertyTraverser ); + relationshipDeleter = new RelationshipDeleter( relationshipGroupGetter, propertyDeleter ); + propertyCreator = new PropertyCreator( neoStores.getPropertyStore(), propertyTraverser ); } catch ( Throwable failure ) { @@ -260,9 +279,10 @@ public void createCommands( { if ( txState != null ) { - NeoStoreTransactionContext context = new NeoStoreTransactionContext( neoStores, loaders, locks ); - TransactionRecordState recordState = new TransactionRecordState( neoStores, integrityValidator, context ); - recordState.initialize( lastTransactionIdWhenStarted ); + RecordChangeSet recordChangeSet = new RecordChangeSet( loaders ); + TransactionRecordState recordState = new TransactionRecordState( neoStores, integrityValidator, + recordChangeSet, lastTransactionIdWhenStarted, locks, + relationshipCreator, relationshipDeleter, propertyCreator, propertyDeleter ); // Visit transaction state and populate these record state objects TxStateVisitor txStateVisitor = new TransactionToRecordStateVisitor( recordState, diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/state/NeoStoreTransactionContext.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/state/NeoStoreTransactionContext.java deleted file mode 100644 index f57ee3769f3b7..0000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/state/NeoStoreTransactionContext.java +++ /dev/null @@ -1,190 +0,0 @@ -/* - * 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 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 . - */ -package org.neo4j.kernel.impl.transaction.state; - -import java.util.Collection; - -import org.neo4j.kernel.impl.core.RelationshipTypeToken; -import org.neo4j.kernel.impl.store.NeoStores; -import org.neo4j.kernel.impl.store.RelationshipGroupStore; -import org.neo4j.kernel.impl.store.record.DynamicRecord; -import org.neo4j.kernel.impl.store.record.LabelTokenRecord; -import org.neo4j.kernel.impl.store.record.NodeRecord; -import org.neo4j.kernel.impl.store.record.PrimitiveRecord; -import org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord; -import org.neo4j.kernel.impl.store.record.PropertyRecord; -import org.neo4j.kernel.impl.store.record.Record; -import org.neo4j.kernel.impl.store.record.RelationshipGroupRecord; -import org.neo4j.kernel.impl.store.record.RelationshipRecord; -import org.neo4j.kernel.impl.store.record.RelationshipTypeTokenRecord; -import org.neo4j.kernel.impl.transaction.state.RecordAccess.RecordProxy; -import org.neo4j.storageengine.api.Token; -import org.neo4j.storageengine.api.lock.ResourceLocker; -import org.neo4j.storageengine.api.schema.SchemaRule; - -public class NeoStoreTransactionContext -{ - private final RelationshipCreator relationshipCreator; - private final RelationshipDeleter relationshipDeleter; - private final PropertyCreator propertyCreator; - private final PropertyDeleter propertyDeleter; - private final RecordAccessSet recordChangeSet; - private final NeoStores neoStores; - private final ResourceLocker locks; - - public NeoStoreTransactionContext( NeoStores neoStores, Loaders loaders, ResourceLocker locks ) - { - this.neoStores = neoStores; - this.locks = locks; - - recordChangeSet = new RecordChangeSet( loaders ); - RelationshipGroupStore relationshipGroupStore = neoStores.getRelationshipGroupStore(); - RelationshipGroupGetter relGroupGetter = new RelationshipGroupGetter( relationshipGroupStore ); - PropertyTraverser propertyTraverser = new PropertyTraverser(); - propertyCreator = new PropertyCreator( neoStores.getPropertyStore(), propertyTraverser ); - propertyDeleter = new PropertyDeleter( neoStores.getPropertyStore(), propertyTraverser ); - relationshipCreator = new RelationshipCreator( - relGroupGetter, relationshipGroupStore.getDenseNodeThreshold() ); - relationshipDeleter = new RelationshipDeleter( relGroupGetter, propertyDeleter ); - } - - public void relationshipDelete( long relId ) - { - relationshipDeleter.relDelete( relId, recordChangeSet, locks ); - } - - public void relationshipCreate( long id, int typeId, long startNodeId, long endNodeId ) - { - relationshipCreator.relationshipCreate( id, typeId, startNodeId, endNodeId, recordChangeSet, locks ); - } - - public void getAndDeletePropertyChain( NodeRecord nodeRecord ) - { - propertyDeleter.deletePropertyChain( nodeRecord, recordChangeSet.getPropertyRecords() ); - } - - public void removeProperty( RecordProxy primitiveProxy, int propertyKey ) - { - propertyDeleter.removeProperty( primitiveProxy, propertyKey, getPropertyRecords() ); - } - - public

void primitiveChangeProperty( RecordProxy primitive, - int propertyKey, Object value ) - { - propertyCreator.primitiveChangeProperty( primitive, propertyKey, value, getPropertyRecords() ); - } - - public

void primitiveAddProperty( RecordProxy primitive, - int propertyKey, Object value ) - { - propertyCreator.primitiveAddProperty( primitive, propertyKey, value, getPropertyRecords() ); - } - - public void createPropertyKeyToken( String name, int id ) - { - TokenCreator creator = - new TokenCreator<>( neoStores.getPropertyKeyTokenStore() ); - creator.createToken( name, id, getPropertyKeyTokenRecords() ); - } - - public void createLabelToken( String name, int id ) - { - TokenCreator creator = - new TokenCreator<>( neoStores.getLabelTokenStore() ); - creator.createToken( name, id, getLabelTokenRecords() ); - } - - public void createRelationshipTypeToken( String name, int id ) - { - TokenCreator creator = - new TokenCreator<>( neoStores.getRelationshipTypeTokenStore() ); - creator.createToken( name, id, getRelationshipTypeTokenRecords() ); - } - - public void clear() - { - recordChangeSet.close(); - } - - public RecordAccess getNodeRecords() - { - return recordChangeSet.getNodeRecords(); - } - - public RecordAccess getRelRecords() - { - return recordChangeSet.getRelRecords(); - } - - public RecordAccess, SchemaRule> getSchemaRuleChanges() - { - return recordChangeSet.getSchemaRuleChanges(); - } - - public RecordAccess getPropertyRecords() - { - return recordChangeSet.getPropertyRecords(); - } - - public RecordAccess getRelGroupRecords() - { - return recordChangeSet.getRelGroupRecords(); - } - - public RecordAccess getPropertyKeyTokenRecords() - { - return recordChangeSet.getPropertyKeyTokenChanges(); - } - - public RecordAccess getLabelTokenRecords() - { - return recordChangeSet.getLabelTokenChanges(); - } - - public RecordAccess getRelationshipTypeTokenRecords() - { - return recordChangeSet.getRelationshipTypeTokenChanges(); - } - - public RecordProxy getRelationshipGroup( NodeRecord node, int type ) - { - long groupId = node.getNextRel(); - long previousGroupId = Record.NO_NEXT_RELATIONSHIP.intValue(); - while ( groupId != Record.NO_NEXT_RELATIONSHIP.intValue() ) - { - RecordProxy change = - recordChangeSet.getRelGroupRecords().getOrLoad( groupId, type ); - RelationshipGroupRecord record = change.forReadingData(); - record.setPrev( previousGroupId ); // not persistent so not a "change" - if ( record.getType() == type ) - { - return change; - } - previousGroupId = groupId; - groupId = record.getNext(); - } - return null; - } - - public boolean hasChanges() - { - return recordChangeSet.hasChanges(); - } -} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/state/RecordAccessSet.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/state/RecordAccessSet.java index cf154857965af..1ec3f6e5b05d8 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/state/RecordAccessSet.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/state/RecordAccessSet.java @@ -52,5 +52,7 @@ public interface RecordAccessSet boolean hasChanges(); + int changeSize(); + void close(); } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/state/RecordChangeSet.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/state/RecordChangeSet.java index 0b7b4598f0c41..c613e3afc420e 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/state/RecordChangeSet.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/state/RecordChangeSet.java @@ -132,6 +132,12 @@ public boolean hasChanges() return changeCounter.value() > 0; } + @Override + public int changeSize() + { + return changeCounter.value(); + } + @Override public void close() { diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/state/TransactionRecordState.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/state/TransactionRecordState.java index 806f5fb654062..add7e3bde6b7a 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/state/TransactionRecordState.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/state/TransactionRecordState.java @@ -29,6 +29,7 @@ import org.neo4j.kernel.api.exceptions.TransactionFailureException; import org.neo4j.kernel.api.properties.DefinedProperty; import org.neo4j.kernel.api.properties.Property; +import org.neo4j.kernel.impl.core.RelationshipTypeToken; import org.neo4j.kernel.impl.store.MetaDataStore; import org.neo4j.kernel.impl.store.NeoStores; import org.neo4j.kernel.impl.store.NodeStore; @@ -51,6 +52,8 @@ import org.neo4j.kernel.impl.util.statistics.IntCounter; import org.neo4j.storageengine.api.StorageCommand; import org.neo4j.storageengine.api.StorageProperty; +import org.neo4j.storageengine.api.Token; +import org.neo4j.storageengine.api.lock.ResourceLocker; import org.neo4j.storageengine.api.schema.SchemaRule; import static org.neo4j.kernel.impl.store.NodeLabelsField.parseLabelsField; @@ -76,55 +79,48 @@ */ public class TransactionRecordState implements RecordState { + private final NeoStores neoStores; private final IntegrityValidator integrityValidator; - private final NeoStoreTransactionContext context; private final NodeStore nodeStore; private final MetaDataStore metaDataStore; private final SchemaStore schemaStore; + private final RecordAccessSet recordChangeSet; + private final long lastCommittedTxWhenTransactionStarted; + private final ResourceLocker locks; + private final RelationshipCreator relationshipCreator; + private final RelationshipDeleter relationshipDeleter; + private final PropertyCreator propertyCreator; + private final PropertyDeleter propertyDeleter; private RecordChanges neoStoreRecord; - private long lastCommittedTxWhenTransactionStarted; private boolean prepared; public TransactionRecordState( NeoStores neoStores, IntegrityValidator integrityValidator, - NeoStoreTransactionContext context ) - { + RecordChangeSet recordChangeSet, long lastCommittedTxWhenTransactionStarted, + ResourceLocker locks, + RelationshipCreator relationshipCreator, + RelationshipDeleter relationshipDeleter, + PropertyCreator propertyCreator, + PropertyDeleter propertyDeleter ) + { + this.neoStores = neoStores; this.nodeStore = neoStores.getNodeStore(); this.metaDataStore = neoStores.getMetaDataStore(); this.schemaStore = neoStores.getSchemaStore(); this.integrityValidator = integrityValidator; - this.context = context; - } - - /** - * Set this record state to a pristine state, acting as if it had never been used. - * - * @param lastCommittedTxWhenTransactionStarted is the highest committed transaction id when this transaction - * begun. No operations in this transaction are allowed to have - * taken place before that transaction id. This is used by - * constraint validation - if a constraint was not online when this - * transaction begun, it will be verified during prepare. If you are - * writing code against this API and are unsure about what to set - * this value to, 0 is a safe choice. That will ensure all - * constraints are checked. - */ - public void initialize( long lastCommittedTxWhenTransactionStarted ) - { + this.recordChangeSet = recordChangeSet; this.lastCommittedTxWhenTransactionStarted = lastCommittedTxWhenTransactionStarted; - prepared = false; - } - - public void clear() - { - // no point in caching neostore record changes since they are rare, let's simply make sure they are cleared - neoStoreRecord = null; - context.clear(); + this.locks = locks; + this.relationshipCreator = relationshipCreator; + this.relationshipDeleter = relationshipDeleter; + this.propertyCreator = propertyCreator; + this.propertyDeleter = propertyDeleter; } @Override public boolean hasChanges() { - return context.hasChanges() || + return recordChangeSet.hasChanges() || (neoStoreRecord != null && neoStoreRecord.changeSize() > 0); } @@ -135,32 +131,27 @@ public void extractCommands( Collection commands ) throws Transa integrityValidator.validateTransactionStartKnowledge( lastCommittedTxWhenTransactionStarted ); - int noOfCommands = context.getNodeRecords().changeSize() + - context.getRelRecords().changeSize() + - context.getPropertyRecords().changeSize() + - context.getSchemaRuleChanges().changeSize() + - context.getPropertyKeyTokenRecords().changeSize() + - context.getLabelTokenRecords().changeSize() + - context.getRelationshipTypeTokenRecords().changeSize() + - context.getRelGroupRecords().changeSize() + + int noOfCommands = recordChangeSet.changeSize() + (neoStoreRecord != null ? neoStoreRecord.changeSize() : 0); - for ( RecordProxy record : context.getLabelTokenRecords().changes() ) + for ( RecordProxy record : recordChangeSet.getLabelTokenChanges().changes() ) { commands.add( new Command.LabelTokenCommand( record.getBefore(), record.forReadingLinkage() ) ); } - for ( RecordProxy record : context.getRelationshipTypeTokenRecords().changes() ) + for ( RecordProxy record : + recordChangeSet.getRelationshipTypeTokenChanges().changes() ) { commands.add( new Command.RelationshipTypeTokenCommand( record.getBefore(), record.forReadingLinkage() ) ); } - for ( RecordProxy record : context.getPropertyKeyTokenRecords().changes() ) + for ( RecordProxy record : + recordChangeSet.getPropertyKeyTokenChanges().changes() ) { commands.add( new Command.PropertyKeyTokenCommand( record.getBefore(), record.forReadingLinkage() ) ); } // Collect nodes, relationships, properties - List nodeCommands = new ArrayList<>( context.getNodeRecords().changeSize() ); - for ( RecordProxy change : context.getNodeRecords().changes() ) + List nodeCommands = new ArrayList<>( recordChangeSet.getNodeRecords().changeSize() ); + for ( RecordProxy change : recordChangeSet.getNodeRecords().changes() ) { NodeRecord record = change.forReadingLinkage(); integrityValidator.validateNodeRecord( record ); @@ -168,22 +159,24 @@ public void extractCommands( Collection commands ) throws Transa } Collections.sort( nodeCommands, COMMAND_SORTER ); - List relCommands = new ArrayList<>( context.getRelRecords().changeSize() ); - for ( RecordProxy change : context.getRelRecords().changes() ) + List relCommands = new ArrayList<>( recordChangeSet.getRelRecords().changeSize() ); + for ( RecordProxy change : recordChangeSet.getRelRecords().changes() ) { relCommands.add( new Command.RelationshipCommand( change.getBefore(), change.forReadingLinkage() ) ); } Collections.sort( relCommands, COMMAND_SORTER ); - List propCommands = new ArrayList<>( context.getPropertyRecords().changeSize() ); - for ( RecordProxy change : context.getPropertyRecords().changes() ) + List propCommands = new ArrayList<>( recordChangeSet.getPropertyRecords().changeSize() ); + for ( RecordProxy change : + recordChangeSet.getPropertyRecords().changes() ) { propCommands.add( new Command.PropertyCommand( change.getBefore(), change.forReadingLinkage() ) ); } Collections.sort( propCommands, COMMAND_SORTER ); - List relGroupCommands = new ArrayList<>( context.getRelGroupRecords().changeSize() ); - for ( RecordProxy change : context.getRelGroupRecords().changes() ) + List relGroupCommands = new ArrayList<>( recordChangeSet.getRelGroupRecords().changeSize() ); + for ( RecordProxy change : + recordChangeSet.getRelGroupRecords().changes() ) { relGroupCommands.add( new Command.RelationshipGroupCommand( change.getBefore(), change.forReadingData() ) ); } @@ -200,7 +193,8 @@ public void extractCommands( Collection commands ) throws Transa commands.add( new Command.NeoStoreCommand( change.getBefore(), change.forReadingData() ) ); } } - for ( RecordProxy, SchemaRule> change : context.getSchemaRuleChanges().changes() ) + for ( RecordProxy, SchemaRule> change : + recordChangeSet.getSchemaRuleChanges().changes() ) { integrityValidator.validateSchemaRule( change.getAdditionalData() ); commands.add( new Command.SchemaRuleCommand( @@ -214,12 +208,12 @@ public void extractCommands( Collection commands ) throws Transa public void relCreate( long id, int typeId, long startNodeId, long endNodeId ) { - context.relationshipCreate( id, typeId, startNodeId, endNodeId ); + relationshipCreator.relationshipCreate( id, typeId, startNodeId, endNodeId, recordChangeSet, locks ); } public void relDelete( long relId ) { - context.relationshipDelete( relId ); + relationshipDeleter.relDelete( relId, recordChangeSet, locks ); } @SafeVarargs @@ -245,7 +239,7 @@ private final void addFiltered( Collection target, Mode mode, */ public void nodeDelete( long nodeId ) { - NodeRecord nodeRecord = context.getNodeRecords().getOrLoad( nodeId, null ).forChangingData(); + NodeRecord nodeRecord = recordChangeSet.getNodeRecords().getOrLoad( nodeId, null ).forChangingData(); if ( !nodeRecord.inUse() ) { throw new IllegalStateException( "Unable to delete Node[" + nodeId + @@ -268,7 +262,7 @@ private Collection markNotInUse( Collection dynami private void getAndDeletePropertyChain( NodeRecord nodeRecord ) { - context.getAndDeletePropertyChain( nodeRecord ); + propertyDeleter.deletePropertyChain( nodeRecord, recordChangeSet.getPropertyRecords() ); } /** @@ -281,8 +275,8 @@ private void getAndDeletePropertyChain( NodeRecord nodeRecord ) */ public void relRemoveProperty( long relId, int propertyKey ) { - RecordProxy rel = context.getRelRecords().getOrLoad( relId, null ); - context.removeProperty( rel, propertyKey ); + RecordProxy rel = recordChangeSet.getRelRecords().getOrLoad( relId, null ); + propertyDeleter.removeProperty( rel, propertyKey, recordChangeSet.getPropertyRecords() ); } /** @@ -294,8 +288,8 @@ public void relRemoveProperty( long relId, int propertyKey ) */ public void nodeRemoveProperty( long nodeId, int propertyKey ) { - RecordProxy node = context.getNodeRecords().getOrLoad( nodeId, null ); - context.removeProperty( node, propertyKey ); + RecordProxy node = recordChangeSet.getNodeRecords().getOrLoad( nodeId, null ); + propertyDeleter.removeProperty( node, propertyKey, recordChangeSet.getPropertyRecords() ); } /** @@ -310,8 +304,8 @@ public void nodeRemoveProperty( long nodeId, int propertyKey ) */ public DefinedProperty relChangeProperty( long relId, int propertyKey, Object value ) { - RecordProxy rel = context.getRelRecords().getOrLoad( relId, null ); - context.primitiveChangeProperty( rel, propertyKey, value ); + RecordProxy rel = recordChangeSet.getRelRecords().getOrLoad( relId, null ); + propertyCreator.primitiveChangeProperty( rel, propertyKey, value, recordChangeSet.getPropertyRecords() ); return Property.property( propertyKey, value ); } @@ -326,8 +320,8 @@ public DefinedProperty relChangeProperty( long relId, int propertyKey, Object va */ public DefinedProperty nodeChangeProperty( long nodeId, int propertyKey, Object value ) { - RecordProxy node = context.getNodeRecords().getOrLoad( nodeId, null ); //getNodeRecord( nodeId ); - context.primitiveChangeProperty( node, propertyKey, value ); + RecordProxy node = recordChangeSet.getNodeRecords().getOrLoad( nodeId, null ); + propertyCreator.primitiveChangeProperty( node, propertyKey, value, recordChangeSet.getPropertyRecords() ); return Property.property( propertyKey, value ); } @@ -342,8 +336,8 @@ public DefinedProperty nodeChangeProperty( long nodeId, int propertyKey, Object */ public DefinedProperty relAddProperty( long relId, int propertyKey, Object value ) { - RecordProxy rel = context.getRelRecords().getOrLoad( relId, null ); - context.primitiveAddProperty( rel, propertyKey, value ); + RecordProxy rel = recordChangeSet.getRelRecords().getOrLoad( relId, null ); + propertyCreator.primitiveAddProperty( rel, propertyKey, value, recordChangeSet.getPropertyRecords() ); return Property.property( propertyKey, value ); } @@ -357,8 +351,8 @@ public DefinedProperty relAddProperty( long relId, int propertyKey, Object value */ public DefinedProperty nodeAddProperty( long nodeId, int propertyKey, Object value ) { - RecordProxy node = context.getNodeRecords().getOrLoad( nodeId, null ); - context.primitiveAddProperty( node, propertyKey, value ); + RecordProxy node = recordChangeSet.getNodeRecords().getOrLoad( nodeId, null ); + propertyCreator.primitiveAddProperty( node, propertyKey, value, recordChangeSet.getPropertyRecords() ); return Property.property( propertyKey, value ); } @@ -369,7 +363,7 @@ public DefinedProperty nodeAddProperty( long nodeId, int propertyKey, Object val */ public void nodeCreate( long nodeId ) { - NodeRecord nodeRecord = context.getNodeRecords().create( nodeId, null ).forChangingData(); + NodeRecord nodeRecord = recordChangeSet.getNodeRecords().create( nodeId, null ).forChangingData(); nodeRecord.setInUse( true ); nodeRecord.setCreated(); } @@ -382,7 +376,9 @@ public void nodeCreate( long nodeId ) */ public void createPropertyKeyToken( String key, int id ) { - context.createPropertyKeyToken( key, id ); + TokenCreator creator = + new TokenCreator<>( neoStores.getPropertyKeyTokenStore() ); + creator.createToken( key, id, recordChangeSet.getPropertyKeyTokenChanges() ); } /** @@ -393,7 +389,9 @@ public void createPropertyKeyToken( String key, int id ) */ public void createLabelToken( String name, int id ) { - context.createLabelToken( name, id ); + TokenCreator creator = + new TokenCreator<>( neoStores.getLabelTokenStore() ); + creator.createToken( name, id, recordChangeSet.getLabelTokenChanges() ); } /** @@ -405,7 +403,9 @@ public void createLabelToken( String name, int id ) */ public void createRelationshipTypeToken( String name, int id ) { - context.createRelationshipTypeToken( name, id ); + TokenCreator creator = + new TokenCreator<>( neoStores.getRelationshipTypeTokenStore() ); + creator.createToken( name, id, recordChangeSet.getRelationshipTypeTokenChanges() ); } private static class CommandSorter implements Comparator @@ -488,7 +488,8 @@ public NeoStoreRecord clone( NeoStoreRecord neoStoreRecord ) */ public DefinedProperty graphAddProperty( int propertyKey, Object value ) { - context.primitiveAddProperty( getOrLoadNeoStoreRecord(), propertyKey, value ); + propertyCreator.primitiveAddProperty( getOrLoadNeoStoreRecord(), propertyKey, value, + recordChangeSet.getPropertyRecords() ); return Property.property( propertyKey, value ); } @@ -502,7 +503,8 @@ public DefinedProperty graphAddProperty( int propertyKey, Object value ) */ public DefinedProperty graphChangeProperty( int propertyKey, Object value ) { - context.primitiveChangeProperty( getOrLoadNeoStoreRecord(), propertyKey, value ); + propertyCreator.primitiveChangeProperty( getOrLoadNeoStoreRecord(), propertyKey, value, + recordChangeSet.getPropertyRecords() ); return Property.property( propertyKey, value ); } @@ -515,12 +517,13 @@ public DefinedProperty graphChangeProperty( int propertyKey, Object value ) public void graphRemoveProperty( int propertyKey ) { RecordProxy recordChange = getOrLoadNeoStoreRecord(); - context.removeProperty( recordChange, propertyKey ); + propertyDeleter.removeProperty( recordChange, propertyKey, recordChangeSet.getPropertyRecords() ); } public void createSchemaRule( SchemaRule schemaRule ) { - for(DynamicRecord change : context.getSchemaRuleChanges().create( schemaRule.getId(), schemaRule ).forChangingData()) + for( DynamicRecord change : recordChangeSet.getSchemaRuleChanges() + .create( schemaRule.getId(), schemaRule ).forChangingData() ) { change.setInUse( true ); change.setCreated(); @@ -530,7 +533,7 @@ public void createSchemaRule( SchemaRule schemaRule ) public void dropSchemaRule( SchemaRule rule ) { RecordProxy, SchemaRule> change = - context.getSchemaRuleChanges().getOrLoad( rule.getId(), rule ); + recordChangeSet.getSchemaRuleChanges().getOrLoad( rule.getId(), rule ); Collection records = change.forChangingData(); for ( DynamicRecord record : records ) { @@ -540,20 +543,20 @@ public void dropSchemaRule( SchemaRule rule ) public void addLabelToNode( int labelId, long nodeId ) { - NodeRecord nodeRecord = context.getNodeRecords().getOrLoad( nodeId, null ).forChangingData(); + NodeRecord nodeRecord = recordChangeSet.getNodeRecords().getOrLoad( nodeId, null ).forChangingData(); parseLabelsField( nodeRecord ).add( labelId, nodeStore, nodeStore.getDynamicLabelStore() ); } public void removeLabelFromNode( int labelId, long nodeId ) { - NodeRecord nodeRecord = context.getNodeRecords().getOrLoad( nodeId, null ).forChangingData(); + NodeRecord nodeRecord = recordChangeSet.getNodeRecords().getOrLoad( nodeId, null ).forChangingData(); parseLabelsField( nodeRecord ).remove( labelId, nodeStore ); } public void setConstraintIndexOwner( IndexRule indexRule, long constraintId ) { RecordProxy, SchemaRule> change = - context.getSchemaRuleChanges().getOrLoad( indexRule.getId(), indexRule ); + recordChangeSet.getSchemaRuleChanges().getOrLoad( indexRule.getId(), indexRule ); Collection records = change.forChangingData(); indexRule = indexRule.withOwningConstraint( constraintId ); diff --git a/community/kernel/src/main/java/org/neo4j/unsafe/batchinsert/DirectRecordAccessSet.java b/community/kernel/src/main/java/org/neo4j/unsafe/batchinsert/DirectRecordAccessSet.java index 64c3157568b8e..ec47993497993 100644 --- a/community/kernel/src/main/java/org/neo4j/unsafe/batchinsert/DirectRecordAccessSet.java +++ b/community/kernel/src/main/java/org/neo4j/unsafe/batchinsert/DirectRecordAccessSet.java @@ -52,7 +52,8 @@ public class DirectRecordAccessSet implements RecordAccessSet private final DirectRecordAccess propertyKeyTokenRecords; private final DirectRecordAccess relationshipTypeTokenRecords; private final DirectRecordAccess labelTokenRecords; -// private final DirectRecordAccess, SchemaRule> schemaRecords; // TODO + // TODO add schema rule access? + private final DirectRecordAccess[] all; public DirectRecordAccessSet( NeoStores neoStores ) { @@ -73,7 +74,10 @@ public DirectRecordAccessSet( NeoStores neoStores ) relationshipTypeTokenRecords = new DirectRecordAccess<>( relationshipTypeTokenStore, loaders.relationshipTypeTokenLoader() ); labelTokenRecords = new DirectRecordAccess<>( labelTokenStore, loaders.labelTokenLoader() ); -// schemaRecords = new DirectRecordAccess<>( neoStores.getSchemaStore(), loaders.schemaRuleLoader() ); // TODO + all = new DirectRecordAccess[] { + nodeRecords, propertyRecords, relationshipRecords, relationshipGroupRecords, + propertyKeyTokenRecords, relationshipTypeTokenRecords, labelTokenRecords + }; } @Override @@ -128,37 +132,41 @@ public RecordAccess getRelationshipT public void close() { commit(); - nodeRecords.close(); - propertyRecords.close(); - relationshipRecords.close(); - relationshipGroupRecords.close(); -// schemaRecords.close(); // TODO - relationshipTypeTokenRecords.close(); - labelTokenRecords.close(); - propertyKeyTokenRecords.close(); + for ( DirectRecordAccess access : all ) + { + access.close(); + } } public void commit() { - nodeRecords.commit(); - propertyRecords.commit(); - relationshipGroupRecords.commit(); - relationshipRecords.commit(); -// schemaRecords.commit(); // TODO - relationshipTypeTokenRecords.commit(); - labelTokenRecords.commit(); - propertyKeyTokenRecords.commit(); + for ( DirectRecordAccess access : all ) + { + access.commit(); + } } @Override public boolean hasChanges() { - return nodeRecords.changeSize() > 0 || - propertyRecords.changeSize() > 0 || - relationshipRecords.changeSize() > 0 || - relationshipGroupRecords.changeSize() > 0 || - propertyKeyTokenRecords.changeSize() > 0 || - labelTokenRecords.changeSize() > 0 || - relationshipTypeTokenRecords.changeSize() > 0; + for ( DirectRecordAccess access : all ) + { + if ( access.changeSize() > 0 ) + { + return true; + } + } + return false; + } + + @Override + public int changeSize() + { + int total = 0; + for ( DirectRecordAccess access : all ) + { + total += access.changeSize(); + } + return total; } } diff --git a/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/store/BatchingRecordAccess.java b/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/store/BatchingRecordAccess.java index 7d5a2bbfbf6a4..22a78afab3f0d 100644 --- a/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/store/BatchingRecordAccess.java +++ b/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/store/BatchingRecordAccess.java @@ -22,13 +22,13 @@ import java.util.Collection; import org.neo4j.helpers.collection.IterableWrapper; -import org.neo4j.kernel.impl.transaction.state.NeoStoreTransactionContext; import org.neo4j.kernel.impl.transaction.state.RecordAccess; +import org.neo4j.kernel.impl.transaction.state.TransactionRecordState; import org.neo4j.kernel.impl.util.collection.ArrayCollection; /** * {@link RecordAccess} optimized for batching and an access pattern where records are created sequentially. - * Mostly here as a bridge between a batch importer and existing record logic in {@link NeoStoreTransactionContext} + * Mostly here as a bridge between a batch importer and existing record logic in {@link TransactionRecordState} * and friends. */ public abstract class BatchingRecordAccess implements RecordAccess diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/RelationshipCreatorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/RelationshipCreatorTest.java index 360c4ca65c8f5..e7f7a40c7d37e 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/RelationshipCreatorTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/RelationshipCreatorTest.java @@ -189,6 +189,12 @@ public boolean hasChanges() { return delegate.hasChanges(); } + + @Override + public int changeSize() + { + return delegate.changeSize(); + } } private static final int DENSE_NODE_THRESHOLD = 5; diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/TransactionRecordStateTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/TransactionRecordStateTest.java index 597bf08b880a5..64be54bda80c3 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/TransactionRecordStateTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/TransactionRecordStateTest.java @@ -43,12 +43,11 @@ import org.neo4j.kernel.impl.api.BatchTransactionApplier; import org.neo4j.kernel.impl.api.CommandVisitor; import org.neo4j.kernel.impl.api.TransactionToApply; -import org.neo4j.kernel.impl.api.index.IndexingService; import org.neo4j.kernel.impl.api.index.NodePropertyCommandsExtractor; import org.neo4j.kernel.impl.core.CacheAccessBackDoor; import org.neo4j.kernel.impl.locking.Lock; import org.neo4j.kernel.impl.locking.LockService; -import org.neo4j.kernel.impl.locking.Locks; +import org.neo4j.kernel.impl.locking.NoOpClient; import org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageCommandReaderFactory; import org.neo4j.kernel.impl.store.NeoStores; import org.neo4j.kernel.impl.store.NodeStore; @@ -77,6 +76,7 @@ import org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader; import org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter; import org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader; +import org.neo4j.kernel.impl.transaction.state.RecordAccess.RecordProxy; import org.neo4j.storageengine.api.StorageCommand; import org.neo4j.storageengine.api.schema.SchemaRule; import org.neo4j.test.NeoStoresRule; @@ -111,48 +111,69 @@ public class TransactionRecordStateTest { private static final String LONG_STRING = "string value long enough not to be stored as a short string"; - public static void assertRelationshipGroupDoesNotExist( NeoStoreTransactionContext txCtx, NodeRecord node, + public static void assertRelationshipGroupDoesNotExist( RecordChangeSet recordChangeSet, NodeRecord node, int type ) { - assertNull( txCtx.getRelationshipGroup( node, type ) ); + assertNull( getRelationshipGroup( recordChangeSet, node, type ) ); } - public static void assertDenseRelationshipCounts( TransactionRecordState tx, NeoStoreTransactionContext txCtx, + public static void assertDenseRelationshipCounts( RecordChangeSet recordChangeSet, long nodeId, int type, int outCount, int inCount ) { - RelationshipGroupRecord group = txCtx.getRelationshipGroup( - txCtx.getNodeRecords().getOrLoad( nodeId, null ).forReadingData(), type ).forReadingData(); + RelationshipGroupRecord group = getRelationshipGroup( recordChangeSet, + recordChangeSet.getNodeRecords().getOrLoad( nodeId, null ).forReadingData(), type ).forReadingData(); assertNotNull( group ); RelationshipRecord rel; long relId = group.getFirstOut(); if ( relId != Record.NO_NEXT_RELATIONSHIP.intValue() ) { - rel = txCtx.getRelRecords().getOrLoad( relId, null ).forReadingData(); + rel = recordChangeSet.getRelRecords().getOrLoad( relId, null ).forReadingData(); // count is stored in the back pointer of the first relationship in the chain assertEquals( "Stored relationship count for OUTGOING differs", outCount, rel.getFirstPrevRel() ); assertEquals( "Manually counted relationships for OUTGOING differs", outCount, - manuallyCountRelationships( txCtx, nodeId, relId ) ); + manuallyCountRelationships( recordChangeSet, nodeId, relId ) ); } relId = group.getFirstIn(); if ( relId != Record.NO_NEXT_RELATIONSHIP.intValue() ) { - rel = txCtx.getRelRecords().getOrLoad( relId, null ).forReadingData(); + rel = recordChangeSet.getRelRecords().getOrLoad( relId, null ).forReadingData(); assertEquals( "Stored relationship count for INCOMING differs", inCount, rel.getSecondPrevRel() ); assertEquals( "Manually counted relationships for INCOMING differs", inCount, - manuallyCountRelationships( txCtx, nodeId, relId ) ); + manuallyCountRelationships( recordChangeSet, nodeId, relId ) ); } } - private static int manuallyCountRelationships( NeoStoreTransactionContext txCtx, long nodeId, long firstRelId ) + private static RecordProxy getRelationshipGroup( + RecordChangeSet recordChangeSet, NodeRecord node, int type ) + { + long groupId = node.getNextRel(); + long previousGroupId = Record.NO_NEXT_RELATIONSHIP.intValue(); + while ( groupId != Record.NO_NEXT_RELATIONSHIP.intValue() ) + { + RecordProxy change = + recordChangeSet.getRelGroupRecords().getOrLoad( groupId, type ); + RelationshipGroupRecord record = change.forReadingData(); + record.setPrev( previousGroupId ); // not persistent so not a "change" + if ( record.getType() == type ) + { + return change; + } + previousGroupId = groupId; + groupId = record.getNext(); + } + return null; + } + + private static int manuallyCountRelationships( RecordChangeSet recordChangeSet, long nodeId, long firstRelId ) { int count = 0; long relId = firstRelId; while ( relId != Record.NO_NEXT_RELATIONSHIP.intValue() ) { count++; - RelationshipRecord record = txCtx.getRelRecords().getOrLoad( relId, null ).forReadingData(); + RelationshipRecord record = recordChangeSet.getRelRecords().getOrLoad( relId, null ).forReadingData(); relId = record.getFirstNode() == nodeId ? record.getFirstNextRel() : record.getSecondNextRel(); } return count; @@ -161,29 +182,28 @@ private static int manuallyCountRelationships( NeoStoreTransactionContext txCtx, @Rule public final NeoStoresRule neoStoresRule = new NeoStoresRule( getClass() ); private final IntegrityValidator integrityValidator = mock( IntegrityValidator.class ); + private RecordChangeSet recordChangeSet; @Test - @SuppressWarnings( "unchecked" ) public void shouldCreateEqualNodePropertyUpdatesOnRecoveryOfCreatedNode() throws Exception { /* There was an issue where recovering a tx where a node with a label and a property * was created resulted in two exact copies of NodePropertyUpdates. */ // GIVEN + NeoStores neoStores = neoStoresRule.open(); long nodeId = 0; int labelId = 5, propertyKeyId = 7; // -- an index long ruleId = 0; - NeoStores neoStores = neoStoresRule.open(); - TransactionRecordState recordState = new TransactionRecordState( neoStores, integrityValidator, - newContext( neoStores ) ); + TransactionRecordState recordState = newTransactionRecordState( neoStores ); SchemaRule rule = indexRule( ruleId, labelId, propertyKeyId, PROVIDER_DESCRIPTOR ); recordState.createSchemaRule( rule ); apply( neoStores, recordState ); // -- and a tx creating a node with that label and property key - recordState = new TransactionRecordState( neoStores, integrityValidator, newContext( neoStores ) ); + recordState = newTransactionRecordState( neoStores ); recordState.nodeCreate( nodeId ); recordState.addLabelToNode( labelId, nodeId ); recordState.nodeAddProperty( nodeId, propertyKeyId, "Neo" ); @@ -223,8 +243,7 @@ public void shouldWriteProperPropertyRecordsWhenOnlyChangingLinkage() throws Exc // GIVEN NeoStores neoStores = neoStoresRule.open(); - TransactionRecordState recordState = new TransactionRecordState( neoStores, integrityValidator, - newContext( neoStores ) ); + TransactionRecordState recordState = newTransactionRecordState( neoStores ); int nodeId = 0; recordState.nodeCreate( nodeId ); int index = 0; @@ -232,7 +251,7 @@ public void shouldWriteProperPropertyRecordsWhenOnlyChangingLinkage() throws Exc apply( neoStores, recordState ); // WHEN - recordState = new TransactionRecordState( neoStores, integrityValidator, newContext( neoStores ) ); + recordState = newTransactionRecordState( neoStores ); int index2 = 1; recordState.nodeAddProperty( nodeId, index2, string( 40 ) ); // will require a block of size 4 @@ -266,10 +285,9 @@ private void verifyPropertyRecord( PropertyRecord record ) public void shouldConvertLabelAdditionToNodePropertyUpdates() throws Exception { // GIVEN - long nodeId = 0; NeoStores neoStores = neoStoresRule.open(); - TransactionRecordState recordState = new TransactionRecordState( neoStores, integrityValidator, - newContext( neoStores ) ); + long nodeId = 0; + TransactionRecordState recordState = newTransactionRecordState( neoStores ); int propertyKey1 = 1, propertyKey2 = 2, labelId = 3; long[] labelIds = new long[]{labelId}; Object value1 = LONG_STRING, value2 = LONG_STRING.getBytes(); @@ -279,7 +297,7 @@ public void shouldConvertLabelAdditionToNodePropertyUpdates() throws Exception apply( neoStores, recordState ); // WHEN - recordState = new TransactionRecordState( neoStores, integrityValidator, newContext( neoStores ) ); + recordState = newTransactionRecordState( neoStores ); recordState.addLabelToNode( labelId, nodeId ); Iterable indexUpdates = indexUpdatesOf( neoStores, recordState ); @@ -294,10 +312,9 @@ public void shouldConvertLabelAdditionToNodePropertyUpdates() throws Exception public void shouldConvertMixedLabelAdditionAndSetPropertyToNodePropertyUpdates() throws Exception { // GIVEN - long nodeId = 0; NeoStores neoStores = neoStoresRule.open(); - TransactionRecordState recordState = new TransactionRecordState( neoStores, integrityValidator, - newContext( neoStores ) ); + long nodeId = 0; + TransactionRecordState recordState = newTransactionRecordState( neoStores ); int propertyKey1 = 1, propertyKey2 = 2, labelId1 = 3, labelId2 = 4; Object value1 = "first", value2 = 4; recordState.nodeCreate( nodeId ); @@ -306,7 +323,7 @@ public void shouldConvertMixedLabelAdditionAndSetPropertyToNodePropertyUpdates() apply( neoStores, recordState ); // WHEN - recordState = new TransactionRecordState( neoStores, integrityValidator, newContext( neoStores ) ); + recordState = newTransactionRecordState( neoStores ); recordState.nodeAddProperty( nodeId, propertyKey2, value2 ); recordState.addLabelToNode( labelId2, nodeId ); Iterable indexUpdates = indexUpdatesOf( neoStores, recordState ); @@ -321,10 +338,9 @@ public void shouldConvertMixedLabelAdditionAndSetPropertyToNodePropertyUpdates() public void shouldConvertLabelRemovalToNodePropertyUpdates() throws Exception { // GIVEN - long nodeId = 0; NeoStores neoStores = neoStoresRule.open(); - TransactionRecordState recordState = new TransactionRecordState( neoStores, integrityValidator, - newContext( neoStores ) ); + long nodeId = 0; + TransactionRecordState recordState = newTransactionRecordState( neoStores ); int propertyKey1 = 1, propertyKey2 = 2, labelId = 3; long[] labelIds = new long[]{labelId}; Object value1 = "first", value2 = 4; @@ -335,7 +351,7 @@ public void shouldConvertLabelRemovalToNodePropertyUpdates() throws Exception apply( neoStores, recordState ); // WHEN - recordState = new TransactionRecordState( neoStores, integrityValidator, newContext( neoStores ) ); + recordState = newTransactionRecordState( neoStores ); recordState.removeLabelFromNode( labelId, nodeId ); Iterable indexUpdates = indexUpdatesOf( neoStores, recordState ); @@ -350,10 +366,9 @@ public void shouldConvertLabelRemovalToNodePropertyUpdates() throws Exception public void shouldConvertMixedLabelRemovalAndRemovePropertyToNodePropertyUpdates() throws Exception { // GIVEN - long nodeId = 0; NeoStores neoStores = neoStoresRule.open(); - TransactionRecordState recordState = new TransactionRecordState( neoStores, integrityValidator, - newContext( neoStores ) ); + long nodeId = 0; + TransactionRecordState recordState = newTransactionRecordState( neoStores ); int propertyKey1 = 1, propertyKey2 = 2, labelId1 = 3, labelId2 = 4; Object value1 = "first", value2 = 4; recordState.nodeCreate( nodeId ); @@ -364,7 +379,7 @@ public void shouldConvertMixedLabelRemovalAndRemovePropertyToNodePropertyUpdates apply( neoStores, recordState ); // WHEN - recordState = new TransactionRecordState( neoStores, integrityValidator, newContext( neoStores ) ); + recordState = newTransactionRecordState( neoStores ); recordState.nodeRemoveProperty( nodeId, property1.propertyKeyId() ); recordState.removeLabelFromNode( labelId2, nodeId ); Iterable indexUpdates = indexUpdatesOf( neoStores, recordState ); @@ -380,10 +395,9 @@ public void shouldConvertMixedLabelRemovalAndRemovePropertyToNodePropertyUpdates public void shouldConvertMixedLabelRemovalAndAddPropertyToNodePropertyUpdates() throws Exception { // GIVEN - long nodeId = 0; NeoStores neoStores = neoStoresRule.open(); - TransactionRecordState recordState = new TransactionRecordState( neoStores, integrityValidator, - newContext( neoStores ) ); + long nodeId = 0; + TransactionRecordState recordState = newTransactionRecordState( neoStores ); int propertyKey1 = 1, propertyKey2 = 2, labelId1 = 3, labelId2 = 4; Object value1 = "first", value2 = 4; recordState.nodeCreate( nodeId ); @@ -393,7 +407,7 @@ public void shouldConvertMixedLabelRemovalAndAddPropertyToNodePropertyUpdates() apply( neoStores, recordState ); // WHEN - recordState = new TransactionRecordState( neoStores, integrityValidator, newContext( neoStores ) ); + recordState = newTransactionRecordState( neoStores ); recordState.nodeAddProperty( nodeId, propertyKey2, value2 ); recordState.removeLabelFromNode( labelId2, nodeId ); Iterable indexUpdates = indexUpdatesOf( neoStores, recordState ); @@ -410,10 +424,9 @@ public void shouldConvertMixedLabelRemovalAndAddPropertyToNodePropertyUpdates() public void shouldConvertChangedPropertyToNodePropertyUpdates() throws Exception { // GIVEN - int nodeId = 0; NeoStores neoStores = neoStoresRule.open(); - TransactionRecordState recordState = new TransactionRecordState( neoStores, integrityValidator, - newContext( neoStores ) ); + int nodeId = 0; + TransactionRecordState recordState = newTransactionRecordState( neoStores ); int propertyKey1 = 1, propertyKey2 = 2; Object value1 = "first", value2 = 4; recordState.nodeCreate( nodeId ); @@ -423,7 +436,7 @@ public void shouldConvertChangedPropertyToNodePropertyUpdates() throws Exception // WHEN Object newValue1 = "new", newValue2 = "new 2"; - recordState = new TransactionRecordState( neoStores, integrityValidator, newContext( neoStores ) ); + recordState = newTransactionRecordState( neoStores ); recordState.nodeChangeProperty( nodeId, property1.propertyKeyId(), newValue1 ); recordState.nodeChangeProperty( nodeId, property2.propertyKeyId(), newValue2 ); Iterable indexUpdates = indexUpdatesOf( neoStores, recordState ); @@ -439,10 +452,9 @@ public void shouldConvertChangedPropertyToNodePropertyUpdates() throws Exception public void shouldConvertRemovedPropertyToNodePropertyUpdates() throws Exception { // GIVEN - int nodeId = 0; NeoStores neoStores = neoStoresRule.open(); - TransactionRecordState recordState = new TransactionRecordState( neoStores, integrityValidator, - newContext( neoStores ) ); + int nodeId = 0; + TransactionRecordState recordState = newTransactionRecordState( neoStores ); int propertyKey1 = 1, propertyKey2 = 2; int labelId = 3; Object value1 = "first", value2 = 4; @@ -453,7 +465,7 @@ public void shouldConvertRemovedPropertyToNodePropertyUpdates() throws Exception apply( neoStores, transactionRepresentationOf( recordState ) ); // WHEN - recordState = new TransactionRecordState( neoStores, integrityValidator, newContext( neoStores ) ); + recordState = newTransactionRecordState( neoStores ); recordState.nodeRemoveProperty( nodeId, property1.propertyKeyId() ); recordState.nodeRemoveProperty( nodeId, property2.propertyKeyId() ); Iterable indexUpdates = indexUpdatesOf( neoStores, recordState ); @@ -511,8 +523,7 @@ public void shouldExtractCreatedCommandsInCorrectOrder() throws Throwable { // GIVEN NeoStores neoStores = neoStoresRule.open( GraphDatabaseSettings.dense_node_threshold.name(), "1" ); - TransactionRecordState recordState = new TransactionRecordState( neoStores, integrityValidator, - newContext( neoStores ) ); + TransactionRecordState recordState = newTransactionRecordState( neoStores ); long nodeId = 0, relId = 1; recordState.nodeCreate( nodeId ); recordState.relCreate( relId++, 0, nodeId, nodeId ); @@ -539,8 +550,7 @@ public void shouldExtractUpdateCommandsInCorrectOrder() throws Throwable { // GIVEN NeoStores neoStores = neoStoresRule.open( GraphDatabaseSettings.dense_node_threshold.name(), "1" ); - TransactionRecordState recordState = new TransactionRecordState( neoStores, integrityValidator, - newContext( neoStores ) ); + TransactionRecordState recordState = newTransactionRecordState( neoStores ); long nodeId = 0, relId1 = 1, relId2 = 2, relId3 = 3; recordState.nodeCreate( nodeId ); recordState.relCreate( relId1, 0, nodeId, nodeId ); @@ -550,8 +560,7 @@ public void shouldExtractUpdateCommandsInCorrectOrder() throws Throwable LockService.NO_LOCK_SERVICE ); apply( applier, transaction( recordState ) ); - recordState = new TransactionRecordState( neoStores, mock( IntegrityValidator.class ), - newContext( neoStores ) ); + recordState = newTransactionRecordState( neoStores ); recordState.nodeChangeProperty( nodeId, 0, 102 ); recordState.relCreate( relId3, 0, nodeId, nodeId ); recordState.relAddProperty( relId1, 0, 123 ); @@ -581,8 +590,7 @@ public void shouldExtractDeleteCommandsInCorrectOrder() throws Throwable { // GIVEN NeoStores neoStores = neoStoresRule.open( GraphDatabaseSettings.dense_node_threshold.name(), "1" ); - TransactionRecordState recordState = new TransactionRecordState( neoStores, integrityValidator, - newContext( neoStores ) ); + TransactionRecordState recordState = newTransactionRecordState( neoStores ); long nodeId1 = 0, nodeId2 = 1, relId1 = 1, relId2 = 2, relId4 = 10; recordState.nodeCreate( nodeId1 ); recordState.nodeCreate( nodeId2 ); @@ -594,8 +602,7 @@ public void shouldExtractDeleteCommandsInCorrectOrder() throws Throwable LockService.NO_LOCK_SERVICE ); apply( applier, transaction( recordState ) ); - recordState = new TransactionRecordState( neoStores, mock( IntegrityValidator.class ), - newContext( neoStores ) ); + recordState = newTransactionRecordState( neoStores ); recordState.relDelete( relId4 ); recordState.nodeDelete( nodeId2 ); recordState.nodeRemoveProperty( nodeId1, 0 ); @@ -624,8 +631,7 @@ public void shouldValidateConstraintIndexAsPartOfExtraction() throws Throwable { // GIVEN NeoStores neoStores = neoStoresRule.open(); - TransactionRecordState recordState = new TransactionRecordState( neoStores, integrityValidator, - newContext( neoStores ) ); + TransactionRecordState recordState = newTransactionRecordState( neoStores ); final long indexId = neoStores.getSchemaStore().nextId(); final long constraintId = neoStores.getSchemaStore().nextId(); @@ -644,8 +650,7 @@ public void shouldCreateProperBeforeAndAfterPropertyCommandsWhenAddingProperty() { // GIVEN NeoStores neoStores = neoStoresRule.open(); - TransactionRecordState recordState = new TransactionRecordState( neoStores, integrityValidator, - newContext( neoStores ) ); + TransactionRecordState recordState = newTransactionRecordState( neoStores ); int nodeId = 1; recordState.nodeCreate( nodeId ); @@ -672,10 +677,9 @@ public void shouldCreateProperBeforeAndAfterPropertyCommandsWhenAddingProperty() public void shouldConvertAddedPropertyToNodePropertyUpdates() throws Exception { // GIVEN - long nodeId = 0; NeoStores neoStores = neoStoresRule.open(); - TransactionRecordState recordState = new TransactionRecordState( neoStores, integrityValidator, - newContext( neoStores ) ); + long nodeId = 0; + TransactionRecordState recordState = newTransactionRecordState( neoStores ); int labelId = 3; int propertyKey1 = 1, propertyKey2 = 2; Object value1 = "first", value2 = 4; @@ -696,7 +700,7 @@ public void shouldConvertAddedPropertyToNodePropertyUpdates() throws Exception public void shouldLockUpdatedNodes() throws Exception { // given - LockService locks = mock( LockService.class, new Answer() + LockService locks = mock( LockService.class, new Answer() { @Override public synchronized Object answer( final InvocationOnMock invocation ) throws Throwable @@ -707,10 +711,7 @@ public synchronized Object answer( final InvocationOnMock invocation ) throws Th { return mock( Lock.class, (Answer) invocationOnMock -> null ); } - else - { - return null; - } + return null; } } ); NeoStores neoStores = neoStoresRule.open(); @@ -721,7 +722,7 @@ public synchronized Object answer( final InvocationOnMock invocation ) throws Th { // create the node records that we will modify in our main tx. - TransactionRecordState tx = recordState( neoStores, newContext( neoStores ) ); + TransactionRecordState tx = newTransactionRecordState( neoStores ); for ( int i = 1; i < nodes.length - 1; i++ ) { tx.nodeCreate( nodes[i] ); @@ -735,7 +736,7 @@ public synchronized Object answer( final InvocationOnMock invocation ) throws Th reset( locks ); // These are the changes we want to assert locking on - TransactionRecordState tx = recordState( neoStores, newContext( neoStores ) ); + TransactionRecordState tx = newTransactionRecordState( neoStores ); tx.nodeCreate( nodes[0] ); tx.addLabelToNode( 0, nodes[1] ); tx.nodeAddProperty( nodes[2], 0, "value" ); @@ -773,7 +774,7 @@ public void movingBilaterallyOfTheDenseNodeThresholdIsConsistent() throws Except { // GIVEN NeoStores neoStores = neoStoresRule.open( GraphDatabaseSettings.dense_node_threshold.name(), "10" ); - TransactionRecordState tx = recordState( neoStores, newContext( neoStores ) ); + TransactionRecordState tx = newTransactionRecordState( neoStores ); long nodeId = neoStores.getNodeStore().nextId(); tx.nodeCreate( nodeId ); @@ -786,7 +787,7 @@ public void movingBilaterallyOfTheDenseNodeThresholdIsConsistent() throws Except LockService.NO_LOCK_SERVICE ); apply( applier, transaction( tx ) ); - tx = recordState( neoStores, newContext( neoStores ) ); + tx = newTransactionRecordState( neoStores ); int typeB = 1; tx.createRelationshipTypeToken( "B", typeB ); @@ -835,7 +836,7 @@ public void createdSchemaRuleRecordMustBeWrittenHeavy() throws Exception { // GIVEN NeoStores neoStores = neoStoresRule.open(); - TransactionRecordState tx = recordState( neoStores, newContext( neoStores ) ); + TransactionRecordState tx = newTransactionRecordState( neoStores ); long ruleId = 0; int labelId = 5, propertyKeyId = 7; SchemaRule rule = new IndexRule( ruleId, labelId, propertyKeyId, @@ -864,8 +865,7 @@ public void shouldConvertToDenseNodeRepresentationWhenHittingThresholdWithDiffer { // GIVEN a node with a total of denseNodeThreshold-1 relationships NeoStores neoStores = neoStoresRule.open( GraphDatabaseSettings.dense_node_threshold.name(), "50" ); - NeoStoreTransactionContext txCtx = newContext( neoStores ); - TransactionRecordState tx = recordState( neoStores, txCtx ); + TransactionRecordState tx = newTransactionRecordState( neoStores ); long nodeId = neoStores.getNodeStore().nextId(); int typeA = 0, typeB = 1, typeC = 2; tx.nodeCreate( nodeId ); @@ -881,16 +881,16 @@ public void shouldConvertToDenseNodeRepresentationWhenHittingThresholdWithDiffer createRelationships( neoStores, tx, nodeId, typeC, OUTGOING, 10 ); createRelationships( neoStores, tx, nodeId, typeC, INCOMING, 10 ); // here we're at the edge - assertFalse( txCtx.getNodeRecords().getOrLoad( nodeId, null ).forReadingData().isDense() ); + assertFalse( recordChangeSet.getNodeRecords().getOrLoad( nodeId, null ).forReadingData().isDense() ); // WHEN creating the relationship that pushes us over the threshold createRelationships( neoStores, tx, nodeId, typeC, INCOMING, 1 ); // THEN the node should have been converted into a dense node - assertTrue( txCtx.getNodeRecords().getOrLoad( nodeId, null ).forReadingData().isDense() ); - assertDenseRelationshipCounts( tx, txCtx, nodeId, typeA, 6, 7 ); - assertDenseRelationshipCounts( tx, txCtx, nodeId, typeB, 8, 9 ); - assertDenseRelationshipCounts( tx, txCtx, nodeId, typeC, 10, 11 ); + assertTrue( recordChangeSet.getNodeRecords().getOrLoad( nodeId, null ).forReadingData().isDense() ); + assertDenseRelationshipCounts( recordChangeSet, nodeId, typeA, 6, 7 ); + assertDenseRelationshipCounts( recordChangeSet, nodeId, typeB, 8, 9 ); + assertDenseRelationshipCounts( recordChangeSet, nodeId, typeC, 10, 11 ); } @Test @@ -899,8 +899,7 @@ public void shouldConvertToDenseNodeRepresentationWhenHittingThresholdWithTheSam { // GIVEN a node with a total of denseNodeThreshold-1 relationships NeoStores neoStores = neoStoresRule.open( GraphDatabaseSettings.dense_node_threshold.name(), "49" ); - NeoStoreTransactionContext txCtx = newContext( neoStores ); - TransactionRecordState tx = recordState( neoStores, txCtx ); + TransactionRecordState tx = newTransactionRecordState( neoStores ); long nodeId = neoStores.getNodeStore().nextId(); int typeA = 0; tx.nodeCreate( nodeId ); @@ -909,14 +908,14 @@ public void shouldConvertToDenseNodeRepresentationWhenHittingThresholdWithTheSam createRelationships( neoStores, tx, nodeId, typeA, INCOMING, 25 ); // here we're at the edge - assertFalse( txCtx.getNodeRecords().getOrLoad( nodeId, null ).forReadingData().isDense() ); + assertFalse( recordChangeSet.getNodeRecords().getOrLoad( nodeId, null ).forReadingData().isDense() ); // WHEN creating the relationship that pushes us over the threshold createRelationships( neoStores, tx, nodeId, typeA, INCOMING, 1 ); // THEN the node should have been converted into a dense node - assertTrue( txCtx.getNodeRecords().getOrLoad( nodeId, null ).forReadingData().isDense() ); - assertDenseRelationshipCounts( tx, txCtx, nodeId, typeA, 24, 26 ); + assertTrue( recordChangeSet.getNodeRecords().getOrLoad( nodeId, null ).forReadingData().isDense() ); + assertDenseRelationshipCounts( recordChangeSet, nodeId, typeA, 24, 26 ); } @Test @@ -925,8 +924,7 @@ public void shouldConvertToDenseNodeRepresentationWhenHittingThresholdWithTheSam { // GIVEN a node with a total of denseNodeThreshold-1 relationships NeoStores neoStores = neoStoresRule.open( GraphDatabaseSettings.dense_node_threshold.name(), "8" ); - NeoStoreTransactionContext txCtx = newContext( neoStores ); - TransactionRecordState tx = recordState( neoStores, txCtx ); + TransactionRecordState tx = newTransactionRecordState( neoStores ); long nodeId = neoStores.getNodeStore().nextId(); int typeA = 0; tx.nodeCreate( nodeId ); @@ -934,14 +932,14 @@ public void shouldConvertToDenseNodeRepresentationWhenHittingThresholdWithTheSam createRelationships( neoStores, tx, nodeId, typeA, OUTGOING, 8 ); // here we're at the edge - assertFalse( txCtx.getNodeRecords().getOrLoad( nodeId, null ).forReadingData().isDense() ); + assertFalse( recordChangeSet.getNodeRecords().getOrLoad( nodeId, null ).forReadingData().isDense() ); // WHEN creating the relationship that pushes us over the threshold createRelationships( neoStores, tx, nodeId, typeA, OUTGOING, 1 ); // THEN the node should have been converted into a dense node - assertTrue( txCtx.getNodeRecords().getOrLoad( nodeId, null ).forReadingData().isDense() ); - assertDenseRelationshipCounts( tx, txCtx, nodeId, typeA, 9, 0 ); + assertTrue( recordChangeSet.getNodeRecords().getOrLoad( nodeId, null ).forReadingData().isDense() ); + assertDenseRelationshipCounts( recordChangeSet, nodeId, typeA, 9, 0 ); } @Test @@ -949,8 +947,7 @@ public void shouldMaintainCorrectDataWhenDeletingFromDenseNodeWithOneType() thro { // GIVEN a node with a total of denseNodeThreshold-1 relationships NeoStores neoStores = neoStoresRule.open( GraphDatabaseSettings.dense_node_threshold.name(), "13" ); - NeoStoreTransactionContext txCtx = newContext( neoStores ); - TransactionRecordState tx = recordState( neoStores, txCtx ); + TransactionRecordState tx = newTransactionRecordState( neoStores ); int nodeId = (int) neoStores.getNodeStore().nextId(), typeA = 0; tx.nodeCreate( nodeId ); tx.createRelationshipTypeToken( "A", typeA ); @@ -960,7 +957,7 @@ public void shouldMaintainCorrectDataWhenDeletingFromDenseNodeWithOneType() thro tx.relDelete( relationshipsCreated[0] ); // THEN the node should have been converted into a dense node - assertDenseRelationshipCounts( tx, txCtx, nodeId, typeA, 0, 14 ); + assertDenseRelationshipCounts( recordChangeSet, nodeId, typeA, 0, 14 ); } @Test @@ -968,8 +965,7 @@ public void shouldMaintainCorrectDataWhenDeletingFromDenseNodeWithManyTypes() th { // GIVEN a node with a total of denseNodeThreshold-1 relationships NeoStores neoStores = neoStoresRule.open( GraphDatabaseSettings.dense_node_threshold.name(), "1" ); - NeoStoreTransactionContext txCtx = newContext( neoStores ); - TransactionRecordState tx = recordState( neoStores, txCtx ); + TransactionRecordState tx = newTransactionRecordState( neoStores ); long nodeId = neoStores.getNodeStore().nextId(); int typeA = 0, typeB = 12, typeC = 600; tx.nodeCreate( nodeId ); @@ -989,57 +985,57 @@ public void shouldMaintainCorrectDataWhenDeletingFromDenseNodeWithManyTypes() th tx.relDelete( relationshipsCreatedAIncoming[0] ); // THEN - assertDenseRelationshipCounts( tx, txCtx, nodeId, typeA, 1, 0 ); - assertDenseRelationshipCounts( tx, txCtx, nodeId, typeB, 1, 1 ); - assertDenseRelationshipCounts( tx, txCtx, nodeId, typeC, 1, 1 ); + assertDenseRelationshipCounts( recordChangeSet, nodeId, typeA, 1, 0 ); + assertDenseRelationshipCounts( recordChangeSet, nodeId, typeB, 1, 1 ); + assertDenseRelationshipCounts( recordChangeSet, nodeId, typeC, 1, 1 ); // WHEN tx.relDelete( relationshipsCreatedAOutgoing[0] ); // THEN - assertRelationshipGroupDoesNotExist( txCtx, txCtx.getNodeRecords().getOrLoad( nodeId, null ).forReadingData(), + assertRelationshipGroupDoesNotExist( recordChangeSet, recordChangeSet.getNodeRecords().getOrLoad( nodeId, null ).forReadingData(), typeA ); - assertDenseRelationshipCounts( tx, txCtx, nodeId, typeB, 1, 1 ); - assertDenseRelationshipCounts( tx, txCtx, nodeId, typeC, 1, 1 ); + assertDenseRelationshipCounts( recordChangeSet, nodeId, typeB, 1, 1 ); + assertDenseRelationshipCounts( recordChangeSet, nodeId, typeC, 1, 1 ); // WHEN tx.relDelete( relationshipsCreatedBIncoming[0] ); // THEN - assertRelationshipGroupDoesNotExist( txCtx, txCtx.getNodeRecords().getOrLoad( nodeId, null ).forReadingData(), + assertRelationshipGroupDoesNotExist( recordChangeSet, recordChangeSet.getNodeRecords().getOrLoad( nodeId, null ).forReadingData(), typeA ); - assertDenseRelationshipCounts( tx, txCtx, nodeId, typeB, 1, 0 ); - assertDenseRelationshipCounts( tx, txCtx, nodeId, typeC, 1, 1 ); + assertDenseRelationshipCounts( recordChangeSet, nodeId, typeB, 1, 0 ); + assertDenseRelationshipCounts( recordChangeSet, nodeId, typeC, 1, 1 ); // WHEN tx.relDelete( relationshipsCreatedBOutgoing[0] ); // THEN - assertRelationshipGroupDoesNotExist( txCtx, txCtx.getNodeRecords().getOrLoad( nodeId, null ).forReadingData(), + assertRelationshipGroupDoesNotExist( recordChangeSet, recordChangeSet.getNodeRecords().getOrLoad( nodeId, null ).forReadingData(), typeA ); - assertRelationshipGroupDoesNotExist( txCtx, txCtx.getNodeRecords().getOrLoad( nodeId, null ).forReadingData(), + assertRelationshipGroupDoesNotExist( recordChangeSet, recordChangeSet.getNodeRecords().getOrLoad( nodeId, null ).forReadingData(), typeB ); - assertDenseRelationshipCounts( tx, txCtx, nodeId, typeC, 1, 1 ); + assertDenseRelationshipCounts( recordChangeSet, nodeId, typeC, 1, 1 ); // WHEN tx.relDelete( relationshipsCreatedCIncoming[0] ); // THEN - assertRelationshipGroupDoesNotExist( txCtx, txCtx.getNodeRecords().getOrLoad( nodeId, null ).forReadingData(), + assertRelationshipGroupDoesNotExist( recordChangeSet, recordChangeSet.getNodeRecords().getOrLoad( nodeId, null ).forReadingData(), typeA ); - assertRelationshipGroupDoesNotExist( txCtx, txCtx.getNodeRecords().getOrLoad( nodeId, null ).forReadingData(), + assertRelationshipGroupDoesNotExist( recordChangeSet, recordChangeSet.getNodeRecords().getOrLoad( nodeId, null ).forReadingData(), typeB ); - assertDenseRelationshipCounts( tx, txCtx, nodeId, typeC, 1, 0 ); + assertDenseRelationshipCounts( recordChangeSet, nodeId, typeC, 1, 0 ); // WHEN tx.relDelete( relationshipsCreatedCOutgoing[0] ); // THEN - assertRelationshipGroupDoesNotExist( txCtx, txCtx.getNodeRecords().getOrLoad( nodeId, null ).forReadingData(), + assertRelationshipGroupDoesNotExist( recordChangeSet, recordChangeSet.getNodeRecords().getOrLoad( nodeId, null ).forReadingData(), typeA ); - assertRelationshipGroupDoesNotExist( txCtx, txCtx.getNodeRecords().getOrLoad( nodeId, null ).forReadingData(), + assertRelationshipGroupDoesNotExist( recordChangeSet, recordChangeSet.getNodeRecords().getOrLoad( nodeId, null ).forReadingData(), typeB ); - assertRelationshipGroupDoesNotExist( txCtx, txCtx.getNodeRecords().getOrLoad( nodeId, null ).forReadingData(), + assertRelationshipGroupDoesNotExist( recordChangeSet, recordChangeSet.getNodeRecords().getOrLoad( nodeId, null ).forReadingData(), typeC ); } @@ -1050,8 +1046,7 @@ public void shouldSortRelationshipGroups() throws Throwable int type5 = 5, type10 = 10, type15 = 15; NeoStores neoStores = neoStoresRule.open( GraphDatabaseSettings.dense_node_threshold.name(), "1" ); { - TransactionRecordState recordState = new TransactionRecordState( neoStores, integrityValidator, - newContext( neoStores ) ); + TransactionRecordState recordState = newTransactionRecordState( neoStores ); neoStores.getRelationshipTypeTokenStore().setHighId( 16 ); recordState.createRelationshipTypeToken( "5", type5 ); @@ -1066,8 +1061,7 @@ public void shouldSortRelationshipGroups() throws Throwable { long otherNode1Id = neoStores.getNodeStore().nextId(); long otherNode2Id = neoStores.getNodeStore().nextId(); - TransactionRecordState recordState = new TransactionRecordState( neoStores, integrityValidator, - newContext( neoStores ) ); + TransactionRecordState recordState = newTransactionRecordState( neoStores ); recordState.nodeCreate( nodeId ); recordState.nodeCreate( otherNode1Id ); recordState.nodeCreate( otherNode2Id ); @@ -1085,8 +1079,7 @@ public void shouldSortRelationshipGroups() throws Throwable // WHEN inserting a relationship of type 5 { - TransactionRecordState recordState = new TransactionRecordState( neoStores, integrityValidator, - newContext( neoStores ) ); + TransactionRecordState recordState = newTransactionRecordState( neoStores ); long otherNodeId = neoStores.getNodeStore().nextId(); recordState.nodeCreate( otherNodeId ); recordState.relCreate( neoStores.getRelationshipStore().nextId(), type5, nodeId, otherNodeId ); @@ -1101,8 +1094,7 @@ public void shouldSortRelationshipGroups() throws Throwable // WHEN inserting a relationship of type 15 { - TransactionRecordState recordState = new TransactionRecordState( neoStores, integrityValidator, - newContext( neoStores ) ); + TransactionRecordState recordState = newTransactionRecordState( neoStores ); long otherNodeId = neoStores.getNodeStore().nextId(); recordState.nodeCreate( otherNodeId ); recordState.relCreate( neoStores.getRelationshipStore().nextId(), type15, nodeId, otherNodeId ); @@ -1177,7 +1169,7 @@ private PhysicalTransactionRepresentation transactionRepresentationOf( Transacti return tx; } - private void assertCommand( StorageCommand next, Class klass ) + private void assertCommand( StorageCommand next, Class klass ) { assertTrue( "Expected " + klass + ". was: " + next, klass.isInstance( next ) ); } @@ -1204,8 +1196,7 @@ private void writeToChannel( TransactionRepresentation transaction, FlushableCha private TransactionRecordState nodeWithDynamicLabelRecord( NeoStores store, AtomicLong nodeId, AtomicLong dynamicLabelRecordId ) { - NeoStoreTransactionContext context = newContext( store ); - TransactionRecordState recordState = recordState( store, context ); + TransactionRecordState recordState = newTransactionRecordState( store ); nodeId.set( store.getNodeStore().nextId() ); int[] labelIds = new int[20]; @@ -1222,7 +1213,7 @@ private TransactionRecordState nodeWithDynamicLabelRecord( NeoStores store, Atom } // Extract the dynamic label record id (which is also a verification that we allocated one) - NodeRecord node = single( context.getNodeRecords().changes() ).forReadingData(); + NodeRecord node = single( recordChangeSet.getNodeRecords().changes() ).forReadingData(); dynamicLabelRecordId.set( single( node.getDynamicLabelRecords() ).getId() ); return recordState; @@ -1230,8 +1221,7 @@ private TransactionRecordState nodeWithDynamicLabelRecord( NeoStores store, Atom private TransactionRecordState deleteNode( NeoStores store, long nodeId ) { - NeoStoreTransactionContext context = newContext( store ); - TransactionRecordState recordState = recordState( store, context ); + TransactionRecordState recordState = newTransactionRecordState( store ); recordState.nodeDelete( nodeId ); return recordState; } @@ -1255,10 +1245,21 @@ private void apply( NeoStores neoStores, TransactionRecordState state ) throws E apply( applier, transactionRepresentationOf( state ) ); } - private TransactionRecordState recordState( NeoStores store, NeoStoreTransactionContext context ) + private TransactionRecordState newTransactionRecordState( NeoStores neoStores ) { - return new TransactionRecordState( store, new IntegrityValidator( store, mock( IndexingService.class ) ), - context ); + Loaders loaders = new Loaders( neoStores ); + recordChangeSet = new RecordChangeSet( loaders ); + PropertyTraverser propertyTraverser = new PropertyTraverser(); + RelationshipGroupGetter relationshipGroupGetter = + new RelationshipGroupGetter( neoStores.getRelationshipGroupStore() ); + PropertyDeleter propertyDeleter = new PropertyDeleter( neoStores.getPropertyStore(), propertyTraverser ); + return new TransactionRecordState( neoStores, integrityValidator, recordChangeSet, 0, + new NoOpClient(), + new RelationshipCreator( relationshipGroupGetter, + neoStores.getRelationshipGroupStore().getDenseNodeThreshold() ), + new RelationshipDeleter( relationshipGroupGetter, propertyDeleter ), + new PropertyCreator( neoStores.getPropertyStore(), propertyTraverser ), + propertyDeleter ); } private TransactionRepresentation transaction( TransactionRecordState recordState ) @@ -1271,11 +1272,6 @@ private TransactionRepresentation transaction( TransactionRecordState recordStat return transaction; } - private NeoStoreTransactionContext newContext( NeoStores neoStores ) - { - return new NeoStoreTransactionContext( neoStores, new Loaders( neoStores ), mock( Locks.Client.class ) ); - } - private void assertDynamicLabelRecordInUse( NeoStores store, long id, boolean inUse ) { DynamicRecord record = store.getNodeStore().getDynamicLabelStore().forceGetRecord( id ); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/WriteTransactionCommandOrderingTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/WriteTransactionCommandOrderingTest.java index 1858fada0c77c..51cd7f0688eb4 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/WriteTransactionCommandOrderingTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/WriteTransactionCommandOrderingTest.java @@ -131,7 +131,7 @@ private PhysicalTransactionRepresentation transactionRepresentationOf( Transacti private TransactionRecordState injectAllPossibleCommands() { - NeoStoreTransactionContext context = mock( NeoStoreTransactionContext.class ); + RecordChangeSet recordChangeSet = mock( RecordChangeSet.class ); RecordChanges labelTokenChanges = mock( RecordChanges.class ); RecordChanges relationshipTypeTokenChanges = @@ -143,14 +143,14 @@ private TransactionRecordState injectAllPossibleCommands() RecordChanges relationshipGroupChanges = mock( RecordChanges.class ); RecordChanges,SchemaRule> schemaRuleChanges = mock( RecordChanges.class ); - when( context.getLabelTokenRecords() ).thenReturn( labelTokenChanges ); - when( context.getRelationshipTypeTokenRecords() ).thenReturn( relationshipTypeTokenChanges ); - when( context.getPropertyKeyTokenRecords() ).thenReturn( propertyKeyTokenChanges ); - when( context.getNodeRecords() ).thenReturn( nodeRecordChanges ); - when( context.getRelRecords() ).thenReturn( relationshipRecordChanges ); - when( context.getPropertyRecords() ).thenReturn( propertyRecordChanges ); - when( context.getRelGroupRecords() ).thenReturn( relationshipGroupChanges ); - when( context.getSchemaRuleChanges() ).thenReturn( schemaRuleChanges ); + when( recordChangeSet.getLabelTokenChanges() ).thenReturn( labelTokenChanges ); + when( recordChangeSet.getRelationshipTypeTokenChanges() ).thenReturn( relationshipTypeTokenChanges ); + when( recordChangeSet.getPropertyKeyTokenChanges() ).thenReturn( propertyKeyTokenChanges ); + when( recordChangeSet.getNodeRecords() ).thenReturn( nodeRecordChanges ); + when( recordChangeSet.getRelRecords() ).thenReturn( relationshipRecordChanges ); + when( recordChangeSet.getPropertyRecords() ).thenReturn( propertyRecordChanges ); + when( recordChangeSet.getRelGroupRecords() ).thenReturn( relationshipGroupChanges ); + when( recordChangeSet.getSchemaRuleChanges() ).thenReturn( schemaRuleChanges ); List> nodeChanges = new LinkedList<>(); @@ -187,7 +187,8 @@ private TransactionRecordState injectAllPossibleCommands() when( schemaRuleChanges.changes() ).thenReturn( Collections.,SchemaRule>>emptyList() ); - return new TransactionRecordState( mock( NeoStores.class ), mock( IntegrityValidator.class ), context ); + return new TransactionRecordState( mock( NeoStores.class ), mock( IntegrityValidator.class ), recordChangeSet, + 0, null, null, null, null, null ); } private static class RecordingPropertyStore extends PropertyStore