diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/command/HighIdTransactionApplier.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/command/HighIdTransactionApplier.java index caca30cd5c123..0a1d67faffa90 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/command/HighIdTransactionApplier.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/command/HighIdTransactionApplier.java @@ -35,6 +35,7 @@ import org.neo4j.kernel.impl.store.record.DynamicRecord; import org.neo4j.kernel.impl.store.record.PropertyBlock; import org.neo4j.kernel.impl.store.record.TokenRecord; +import org.neo4j.kernel.impl.transaction.command.Command.BaseCommand; import org.neo4j.kernel.impl.transaction.command.Command.LabelTokenCommand; import org.neo4j.kernel.impl.transaction.command.Command.NodeCommand; import org.neo4j.kernel.impl.transaction.command.Command.PropertyCommand; @@ -46,6 +47,8 @@ import org.neo4j.kernel.impl.transaction.command.Command.TokenCommand; import org.neo4j.storageengine.api.Token; +import static java.lang.Math.max; + public class HighIdTransactionApplier extends TransactionApplier.Adapter { private final NeoStores neoStores; @@ -129,7 +132,7 @@ public boolean visitSchemaRuleCommand( SchemaRuleCommand command ) throws IOExce SchemaStore schemaStore = neoStores.getSchemaStore(); for ( DynamicRecord record : command.getRecordsAfter() ) { - track( schemaStore, record.getId() ); + track( schemaStore, record ); } return false; } @@ -145,8 +148,9 @@ public void close() throws Exception } } - private void track( RecordStore store, long id ) + private void track( RecordStore store, AbstractBaseRecord record ) { + long id = max( record.getId(), record.requiresSecondaryUnit() ? record.getSecondaryUnitId() : -1 ); HighId highId = highIds.get( store ); if ( highId == null ) { @@ -158,23 +162,23 @@ private void track( RecordStore store, long id ) } } - private void track( RecordStore store, Command command ) + private void track( RecordStore store, BaseCommand command ) { - track( store, command.getKey() ); + track( store, command.getAfter() ); } private void track( RecordStore store, Collection records ) { for ( AbstractBaseRecord record : records ) { - track( store, record.getId() ); + track( store, record ); } } private void trackToken( TokenStore tokenStore, TokenCommand tokenCommand ) { - track( tokenStore, tokenCommand ); + track( tokenStore, tokenCommand.getAfter() ); track( tokenStore.getNameStore(), tokenCommand.getAfter().getNameRecords() ); } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/command/HighIdTransactionApplierTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/command/HighIdTransactionApplierTest.java index d38b89ace13ff..1210d6923d65f 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/command/HighIdTransactionApplierTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/command/HighIdTransactionApplierTest.java @@ -24,6 +24,12 @@ import org.neo4j.kernel.impl.store.NeoStores; import org.neo4j.kernel.impl.store.PropertyType; +import org.neo4j.kernel.impl.store.record.NodeRecord; +import org.neo4j.kernel.impl.store.record.RelationshipGroupRecord; +import org.neo4j.kernel.impl.store.record.RelationshipRecord; +import org.neo4j.kernel.impl.transaction.command.Command.NodeCommand; +import org.neo4j.kernel.impl.transaction.command.Command.RelationshipCommand; +import org.neo4j.kernel.impl.transaction.command.Command.RelationshipGroupCommand; import org.neo4j.test.NeoStoresRule; import static org.junit.Assert.assertEquals; @@ -95,4 +101,39 @@ public void shouldUpdateHighIdsOnExternalTransaction() throws Exception assertEquals( "PropertyStore DynamicArrayStore", 9 + 1, neoStores.getPropertyStore().getArrayStore().getHighId() ); assertEquals( "SchemaStore", 20 + 1, neoStores.getSchemaStore().getHighId() ); } + + @Test + public void shouldTrackSecondaryUnitIdsAsWell() throws Exception + { + // GIVEN + NeoStores neoStores = neoStoresRule.open(); + HighIdTransactionApplier tracker = new HighIdTransactionApplier( neoStores ); + + NodeRecord node = new NodeRecord( 5 ).initialize( true, 123, true, 456, 0 ); + node.setSecondaryUnitId( 6 ); + node.setRequiresSecondaryUnit( true ); + + RelationshipRecord relationship = new RelationshipRecord( 10 ) + .initialize( true, 1, 2, 3, 4, 5, 6, 7, 8, true, true ); + relationship.setSecondaryUnitId( 12 ); + relationship.setRequiresSecondaryUnit( true ); + + RelationshipGroupRecord relationshipGroup = new RelationshipGroupRecord( 8 ) + .initialize( true, 0, 1, 2, 3, 4, 5 ); + relationshipGroup.setSecondaryUnitId( 20 ); + relationshipGroup.setRequiresSecondaryUnit( true ); + + // WHEN + tracker.visitNodeCommand( new NodeCommand( new NodeRecord( node.getId() ), node ) ); + tracker.visitRelationshipCommand( new RelationshipCommand( + new RelationshipRecord( relationship.getId() ), relationship ) ); + tracker.visitRelationshipGroupCommand( new RelationshipGroupCommand( + new RelationshipGroupRecord( relationshipGroup.getId() ), relationshipGroup ) ); + tracker.close(); + + // THEN + assertEquals( node.getSecondaryUnitId()+1, neoStores.getNodeStore().getHighId() ); + assertEquals( relationship.getSecondaryUnitId()+1, neoStores.getRelationshipStore().getHighId() ); + assertEquals( relationshipGroup.getSecondaryUnitId()+1, neoStores.getRelationshipGroupStore().getHighId() ); + } }