From 1e3d499816126a53a1645fc6a528f634cd2664b0 Mon Sep 17 00:00:00 2001 From: lutovich Date: Sun, 7 Aug 2016 20:23:11 +0200 Subject: [PATCH] All CheckTxLogs checks compare !inUse records only by id Used records are compared by all other record-specific fields. --- .../tools/txlog/checktypes/CheckType.java | 27 ++++++++- .../txlog/checktypes/NeoStoreCheckType.java | 7 +-- .../tools/txlog/checktypes/NodeCheckType.java | 11 +--- .../txlog/checktypes/PropertyCheckType.java | 18 +----- .../checktypes/RelationshipCheckType.java | 36 +---------- .../RelationshipGroupCheckType.java | 11 +--- .../checktypes/NeoStoreCheckTypeTest.java | 56 ++++++++++++++++++ .../txlog/checktypes/NodeCheckTypeTest.java | 59 +++++++++++++++++++ .../checktypes/PropertyCheckTypeTest.java | 59 +++++++++++++++++++ .../RelationshipGroupCheckTypeTest.java | 59 +++++++++++++++++++ 10 files changed, 267 insertions(+), 76 deletions(-) create mode 100644 tools/src/test/java/org/neo4j/tools/txlog/checktypes/NeoStoreCheckTypeTest.java create mode 100644 tools/src/test/java/org/neo4j/tools/txlog/checktypes/NodeCheckTypeTest.java create mode 100644 tools/src/test/java/org/neo4j/tools/txlog/checktypes/PropertyCheckTypeTest.java create mode 100644 tools/src/test/java/org/neo4j/tools/txlog/checktypes/RelationshipGroupCheckTypeTest.java diff --git a/tools/src/main/java/org/neo4j/tools/txlog/checktypes/CheckType.java b/tools/src/main/java/org/neo4j/tools/txlog/checktypes/CheckType.java index 748a0d0b5bf2b..3b0cc70577d75 100644 --- a/tools/src/main/java/org/neo4j/tools/txlog/checktypes/CheckType.java +++ b/tools/src/main/java/org/neo4j/tools/txlog/checktypes/CheckType.java @@ -19,6 +19,8 @@ */ package org.neo4j.tools.txlog.checktypes; +import java.util.Objects; + import org.neo4j.kernel.impl.store.record.AbstractBaseRecord; import org.neo4j.kernel.impl.transaction.command.Command; import org.neo4j.kernel.impl.transaction.command.Command.NodeCommand; @@ -51,7 +53,30 @@ public Class commandClass() public abstract R after( C command ); - public abstract boolean equal( R record1, R record2 ); + public final boolean equal( R record1, R record2 ) + { + Objects.requireNonNull( record1 ); + Objects.requireNonNull( record2 ); + + if ( record1.getId() != record2.getId() ) + { + return false; + } + else if ( record1.inUse() != record2.inUse() ) + { + return false; + } + else if ( !record1.inUse() ) + { + return true; + } + else + { + return inUseRecordsEqual( record1, record2 ); + } + } + + protected abstract boolean inUseRecordsEqual( R record1, R record2 ); public abstract String name(); } diff --git a/tools/src/main/java/org/neo4j/tools/txlog/checktypes/NeoStoreCheckType.java b/tools/src/main/java/org/neo4j/tools/txlog/checktypes/NeoStoreCheckType.java index 6eb88f1bb8ecf..8a599280b5867 100644 --- a/tools/src/main/java/org/neo4j/tools/txlog/checktypes/NeoStoreCheckType.java +++ b/tools/src/main/java/org/neo4j/tools/txlog/checktypes/NeoStoreCheckType.java @@ -19,8 +19,6 @@ */ package org.neo4j.tools.txlog.checktypes; -import java.util.Objects; - import org.neo4j.kernel.impl.store.record.NeoStoreRecord; import org.neo4j.kernel.impl.transaction.command.Command; @@ -44,11 +42,8 @@ public NeoStoreRecord after( Command.NeoStoreCommand command ) } @Override - public boolean equal( NeoStoreRecord record1, NeoStoreRecord record2 ) + protected boolean inUseRecordsEqual( NeoStoreRecord record1, NeoStoreRecord record2 ) { - Objects.requireNonNull( record1 ); - Objects.requireNonNull( record2 ); - return record1.getNextProp() == record2.getNextProp(); } diff --git a/tools/src/main/java/org/neo4j/tools/txlog/checktypes/NodeCheckType.java b/tools/src/main/java/org/neo4j/tools/txlog/checktypes/NodeCheckType.java index c8cf6d3dc570f..b14cb4fb03a26 100644 --- a/tools/src/main/java/org/neo4j/tools/txlog/checktypes/NodeCheckType.java +++ b/tools/src/main/java/org/neo4j/tools/txlog/checktypes/NodeCheckType.java @@ -19,8 +19,6 @@ */ package org.neo4j.tools.txlog.checktypes; -import java.util.Objects; - import org.neo4j.kernel.impl.store.record.NodeRecord; import org.neo4j.kernel.impl.transaction.command.Command; @@ -44,14 +42,9 @@ public NodeRecord after( Command.NodeCommand command ) } @Override - public boolean equal( NodeRecord record1, NodeRecord record2 ) + protected boolean inUseRecordsEqual( NodeRecord record1, NodeRecord record2 ) { - Objects.requireNonNull( record1 ); - Objects.requireNonNull( record2 ); - - return record1.getId() == record2.getId() && - record1.inUse() == record2.inUse() && - record1.getNextProp() == record2.getNextProp() && + return record1.getNextProp() == record2.getNextProp() && record1.getNextRel() == record2.getNextRel() && record1.isDense() == record2.isDense() && record1.getLabelField() == record2.getLabelField(); diff --git a/tools/src/main/java/org/neo4j/tools/txlog/checktypes/PropertyCheckType.java b/tools/src/main/java/org/neo4j/tools/txlog/checktypes/PropertyCheckType.java index 9f1134f1d5f8c..0f9457c71798c 100644 --- a/tools/src/main/java/org/neo4j/tools/txlog/checktypes/PropertyCheckType.java +++ b/tools/src/main/java/org/neo4j/tools/txlog/checktypes/PropertyCheckType.java @@ -22,7 +22,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Objects; import org.neo4j.kernel.impl.store.record.PropertyBlock; import org.neo4j.kernel.impl.store.record.PropertyRecord; @@ -48,23 +47,8 @@ public PropertyRecord after( Command.PropertyCommand command ) } @Override - public boolean equal( PropertyRecord record1, PropertyRecord record2 ) + protected boolean inUseRecordsEqual( PropertyRecord record1, PropertyRecord record2 ) { - Objects.requireNonNull( record1 ); - Objects.requireNonNull( record2 ); - - if ( record1.getId() != record2.getId() ) - { - return false; - } - if ( record1.inUse() != record2.inUse() ) - { - return false; - } - if ( !record1.inUse() ) - { - return true; - } return record1.isNodeSet() == record2.isNodeSet() && record1.isRelSet() == record2.isRelSet() && record1.getNodeId() == record2.getNodeId() && diff --git a/tools/src/main/java/org/neo4j/tools/txlog/checktypes/RelationshipCheckType.java b/tools/src/main/java/org/neo4j/tools/txlog/checktypes/RelationshipCheckType.java index 173b91f645d65..f1efda1b5e66c 100644 --- a/tools/src/main/java/org/neo4j/tools/txlog/checktypes/RelationshipCheckType.java +++ b/tools/src/main/java/org/neo4j/tools/txlog/checktypes/RelationshipCheckType.java @@ -19,13 +19,8 @@ */ package org.neo4j.tools.txlog.checktypes; -import java.util.Objects; - import org.neo4j.kernel.impl.store.record.RelationshipRecord; import org.neo4j.kernel.impl.transaction.command.Command; -import org.neo4j.kernel.impl.transaction.command.PhysicalLogCommandReaderV3_0_2; -import org.neo4j.storageengine.api.ReadableChannel; -import org.neo4j.storageengine.api.WritableChannel; public class RelationshipCheckType extends CheckType { @@ -46,36 +41,10 @@ public RelationshipRecord after( Command.RelationshipCommand command ) return command.getAfter(); } - /** - * Checks that two given {@link RelationshipRecord}s are equal. {@link RelationshipRecord#inUse() Used} - * records are compared by all present fields/pointers. Unused records are compared only by id. This is so - * because for removed relationships we write not only inUse flag but also - * {@link RelationshipRecord#getType() relationship type} in - * {@link Command.RelationshipCommand#serialize(WritableChannel)} and read it in - * {@link PhysicalLogCommandReaderV3_0_2#readRelationshipRecord(long, ReadableChannel)}. - * - * @param record1 first record to check. - * @param record2 second record to check. - * @return {@code true} when records are equal, otherwise {@code false}. - */ @Override - public boolean equal( RelationshipRecord record1, RelationshipRecord record2 ) + protected boolean inUseRecordsEqual( RelationshipRecord record1, RelationshipRecord record2 ) { - Objects.requireNonNull( record1 ); - Objects.requireNonNull( record2 ); - - if ( record1.getId() != record2.getId() ) - { - return false; - } - - if ( record1.inUse() == record2.inUse() && !record1.inUse() ) - { - return true; - } - - return record1.inUse() == record2.inUse() && - record1.getNextProp() == record2.getNextProp() && + return record1.getNextProp() == record2.getNextProp() && record1.isFirstInFirstChain() == record2.isFirstInFirstChain() && record1.isFirstInSecondChain() == record2.isFirstInSecondChain() && record1.getFirstNextRel() == record2.getFirstNextRel() && @@ -87,7 +56,6 @@ public boolean equal( RelationshipRecord record1, RelationshipRecord record2 ) record1.getType() == record2.getType(); } - @Override public String name() { diff --git a/tools/src/main/java/org/neo4j/tools/txlog/checktypes/RelationshipGroupCheckType.java b/tools/src/main/java/org/neo4j/tools/txlog/checktypes/RelationshipGroupCheckType.java index cf0206be86fbf..4471ee131d2a7 100644 --- a/tools/src/main/java/org/neo4j/tools/txlog/checktypes/RelationshipGroupCheckType.java +++ b/tools/src/main/java/org/neo4j/tools/txlog/checktypes/RelationshipGroupCheckType.java @@ -19,8 +19,6 @@ */ package org.neo4j.tools.txlog.checktypes; -import java.util.Objects; - import org.neo4j.kernel.impl.store.record.RelationshipGroupRecord; import org.neo4j.kernel.impl.transaction.command.Command; @@ -44,14 +42,9 @@ public RelationshipGroupRecord after( Command.RelationshipGroupCommand command ) } @Override - public boolean equal( RelationshipGroupRecord record1, RelationshipGroupRecord record2 ) + protected boolean inUseRecordsEqual( RelationshipGroupRecord record1, RelationshipGroupRecord record2 ) { - Objects.requireNonNull( record1 ); - Objects.requireNonNull( record2 ); - - return record1.getId() == record2.getId() && - record1.inUse() == record2.inUse() && - record1.getFirstIn() == record2.getFirstIn() && + return record1.getFirstIn() == record2.getFirstIn() && record1.getFirstLoop() == record2.getFirstLoop() && record1.getFirstOut() == record2.getFirstOut() && record1.getNext() == record2.getNext() && diff --git a/tools/src/test/java/org/neo4j/tools/txlog/checktypes/NeoStoreCheckTypeTest.java b/tools/src/test/java/org/neo4j/tools/txlog/checktypes/NeoStoreCheckTypeTest.java new file mode 100644 index 0000000000000..9c4f43c49346f --- /dev/null +++ b/tools/src/test/java/org/neo4j/tools/txlog/checktypes/NeoStoreCheckTypeTest.java @@ -0,0 +1,56 @@ +/* + * 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 Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.neo4j.tools.txlog.checktypes; + +import org.junit.Test; + +import org.neo4j.kernel.impl.store.record.NeoStoreRecord; + +import static org.junit.Assert.assertTrue; + +public class NeoStoreCheckTypeTest +{ + @Test + public void inUseRecordEquality() + { + NeoStoreRecord record1 = new NeoStoreRecord(); + record1.initialize( true, 1 ); + + NeoStoreRecord record2 = record1.clone(); + + NeoStoreCheckType check = new NeoStoreCheckType(); + + assertTrue( check.equal( record1, record2 ) ); + } + + @Test + public void notInUseRecordEquality() + { + NeoStoreRecord record1 = new NeoStoreRecord(); + record1.initialize( false, 1 ); + + NeoStoreRecord record2 = new NeoStoreRecord(); + record2.initialize( false, 11 ); + + NeoStoreCheckType check = new NeoStoreCheckType(); + + assertTrue( check.equal( record1, record2 ) ); + } +} diff --git a/tools/src/test/java/org/neo4j/tools/txlog/checktypes/NodeCheckTypeTest.java b/tools/src/test/java/org/neo4j/tools/txlog/checktypes/NodeCheckTypeTest.java new file mode 100644 index 0000000000000..8e78c55aa35c7 --- /dev/null +++ b/tools/src/test/java/org/neo4j/tools/txlog/checktypes/NodeCheckTypeTest.java @@ -0,0 +1,59 @@ +/* + * 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 Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.neo4j.tools.txlog.checktypes; + +import org.junit.Test; + +import org.neo4j.kernel.impl.store.record.NodeRecord; + +import static org.junit.Assert.assertTrue; + +public class NodeCheckTypeTest +{ + @Test + public void inUseRecordEquality() + { + NodeRecord record1 = new NodeRecord( 1 ); + record1.initialize( true, 1, false, 2, 3 ); + record1.setSecondaryUnitId( 42 ); + + NodeRecord record2 = record1.clone(); + + NodeCheckType check = new NodeCheckType(); + + assertTrue( check.equal( record1, record2 ) ); + } + + @Test + public void notInUseRecordEquality() + { + NodeRecord record1 = new NodeRecord( 1 ); + record1.initialize( false, 1, true, 2, 3 ); + record1.setSecondaryUnitId( 42 ); + + NodeRecord record2 = new NodeRecord( 1 ); + record2.initialize( false, 11, true, 22, 33 ); + record2.setSecondaryUnitId( 24 ); + + NodeCheckType check = new NodeCheckType(); + + assertTrue( check.equal( record1, record2 ) ); + } +} diff --git a/tools/src/test/java/org/neo4j/tools/txlog/checktypes/PropertyCheckTypeTest.java b/tools/src/test/java/org/neo4j/tools/txlog/checktypes/PropertyCheckTypeTest.java new file mode 100644 index 0000000000000..7286c50830604 --- /dev/null +++ b/tools/src/test/java/org/neo4j/tools/txlog/checktypes/PropertyCheckTypeTest.java @@ -0,0 +1,59 @@ +/* + * 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 Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.neo4j.tools.txlog.checktypes; + +import org.junit.Test; + +import org.neo4j.kernel.impl.store.record.PropertyRecord; + +import static org.junit.Assert.assertTrue; + +public class PropertyCheckTypeTest +{ + @Test + public void inUseRecordEquality() + { + PropertyRecord record1 = new PropertyRecord( 1 ); + record1.initialize( true, 1, 2 ); + record1.setSecondaryUnitId( 42 ); + + PropertyRecord record2 = record1.clone(); + + PropertyCheckType check = new PropertyCheckType(); + + assertTrue( check.equal( record1, record2 ) ); + } + + @Test + public void notInUseRecordEquality() + { + PropertyRecord record1 = new PropertyRecord( 1 ); + record1.initialize( false, 1, 2 ); + record1.setSecondaryUnitId( 42 ); + + PropertyRecord record2 = new PropertyRecord( 1 ); + record2.initialize( false, 11, 22 ); + record2.setSecondaryUnitId( 24 ); + + PropertyCheckType check = new PropertyCheckType(); + + assertTrue( check.equal( record1, record2 ) ); + } +} diff --git a/tools/src/test/java/org/neo4j/tools/txlog/checktypes/RelationshipGroupCheckTypeTest.java b/tools/src/test/java/org/neo4j/tools/txlog/checktypes/RelationshipGroupCheckTypeTest.java new file mode 100644 index 0000000000000..cbaf7950e1d2d --- /dev/null +++ b/tools/src/test/java/org/neo4j/tools/txlog/checktypes/RelationshipGroupCheckTypeTest.java @@ -0,0 +1,59 @@ +/* + * 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 Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.neo4j.tools.txlog.checktypes; + +import org.junit.Test; + +import org.neo4j.kernel.impl.store.record.RelationshipGroupRecord; + +import static org.junit.Assert.assertTrue; + +public class RelationshipGroupCheckTypeTest +{ + @Test + public void inUseRecordEquality() + { + RelationshipGroupRecord record1 = new RelationshipGroupRecord( 1 ); + record1.initialize( true, 1, 2, 3, 4, 5, 6 ); + record1.setSecondaryUnitId( 42 ); + + RelationshipGroupRecord record2 = record1.clone(); + + RelationshipGroupCheckType check = new RelationshipGroupCheckType(); + + assertTrue( check.equal( record1, record2 ) ); + } + + @Test + public void notInUseRecordEquality() + { + RelationshipGroupRecord record1 = new RelationshipGroupRecord( 1 ); + record1.initialize( false, 1, 2, 3, 4, 5, 6 ); + record1.setSecondaryUnitId( 42 ); + + RelationshipGroupRecord record2 = new RelationshipGroupRecord( 1 ); + record1.initialize( false, 11, 22, 33, 44, 55, 66 ); + record2.setSecondaryUnitId( 24 ); + + RelationshipGroupCheckType check = new RelationshipGroupCheckType(); + + assertTrue( check.equal( record1, record2 ) ); + } +}