Skip to content

Commit

Permalink
All CheckTxLogs checks compare !inUse records only by id
Browse files Browse the repository at this point in the history
Used records are compared by all other record-specific fields.
  • Loading branch information
lutovich committed Aug 7, 2016
1 parent 8733202 commit 1e3d499
Show file tree
Hide file tree
Showing 10 changed files with 267 additions and 76 deletions.
Expand Up @@ -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;
Expand Down Expand Up @@ -51,7 +53,30 @@ public Class<C> 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();
}
Expand Up @@ -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;

Expand All @@ -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();
}

Expand Down
Expand Up @@ -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;

Expand All @@ -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();
Expand Down
Expand Up @@ -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;
Expand All @@ -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() &&
Expand Down
Expand Up @@ -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<Command.RelationshipCommand,RelationshipRecord>
{
Expand All @@ -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() &&
Expand All @@ -87,7 +56,6 @@ public boolean equal( RelationshipRecord record1, RelationshipRecord record2 )
record1.getType() == record2.getType();
}


@Override
public String name()
{
Expand Down
Expand Up @@ -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;

Expand All @@ -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() &&
Expand Down
@@ -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 <http://www.gnu.org/licenses/>.
*/
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 ) );
}
}
@@ -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 <http://www.gnu.org/licenses/>.
*/
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 ) );
}
}
@@ -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 <http://www.gnu.org/licenses/>.
*/
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 ) );
}
}

0 comments on commit 1e3d499

Please sign in to comment.