Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make sure reserved ID is skipped in batch importer
Parallel batch importer assigns/tracks record ids using it's own id sequence. Sequence is aware of the special reserved id IdGeneratorImpl.INTEGER_MINUS_ONE. However, PBI also reads batches of records directly from the store using raw ids. This code was not aware of the reserved id and tried to read and write records with such id. Doing this caused exceptions from the store layer. This commit makes sure records with reserved ids are never returned as part of a PBI's records batch. As a safety, measure it also makes sure record with reserved id is never written to the store.
- Loading branch information
Showing
9 changed files
with
353 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...unity/kernel/src/test/java/org/neo4j/unsafe/impl/batchimport/ReadNodeRecordsStepTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* 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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.unsafe.impl.batchimport; | ||
|
||
import org.junit.Test; | ||
|
||
import java.util.Arrays; | ||
import java.util.function.Predicate; | ||
import java.util.stream.Stream; | ||
|
||
import org.neo4j.kernel.impl.store.NodeStore; | ||
import org.neo4j.kernel.impl.store.id.IdGeneratorImpl; | ||
import org.neo4j.kernel.impl.store.record.NodeRecord; | ||
import org.neo4j.unsafe.impl.batchimport.staging.StageControl; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class ReadNodeRecordsStepTest | ||
{ | ||
@Test | ||
public void reservedIdIsSkipped() | ||
{ | ||
long highId = 5; | ||
int batchSize = (int) highId; | ||
NodeStore store = StoreWithReservedId.newNodeStoreMock( highId ); | ||
when( store.getHighId() ).thenReturn( highId ); | ||
|
||
ReadNodeRecordsStep step = new ReadNodeRecordsStep( mock( StageControl.class ), Configuration.DEFAULT, store ); | ||
|
||
Object batch = step.nextBatchOrNull( 0, batchSize ); | ||
|
||
assertNotNull( batch ); | ||
|
||
NodeRecord[] records = (NodeRecord[]) batch; | ||
boolean hasRecordWithReservedId = Stream.of( records ).anyMatch( recordWithReservedId() ); | ||
assertFalse( "Batch contains record with reserved id " + Arrays.toString( records ), hasRecordWithReservedId ); | ||
} | ||
|
||
private static Predicate<NodeRecord> recordWithReservedId() | ||
{ | ||
return record -> record.getId() == IdGeneratorImpl.INTEGER_MINUS_ONE; | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
...test/java/org/neo4j/unsafe/impl/batchimport/ReadRelationshipRecordsBackwardsStepTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* 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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.unsafe.impl.batchimport; | ||
|
||
import org.junit.Test; | ||
|
||
import java.util.Arrays; | ||
import java.util.function.Predicate; | ||
import java.util.stream.Stream; | ||
|
||
import org.neo4j.kernel.impl.store.RelationshipStore; | ||
import org.neo4j.kernel.impl.store.id.IdGeneratorImpl; | ||
import org.neo4j.kernel.impl.store.record.RelationshipRecord; | ||
import org.neo4j.unsafe.impl.batchimport.staging.StageControl; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class ReadRelationshipRecordsBackwardsStepTest | ||
{ | ||
@Test | ||
public void reservedIdIsSkipped() | ||
{ | ||
long highId = 5; | ||
int batchSize = (int) highId; | ||
RelationshipStore store = StoreWithReservedId.newRelationshipStoreMock( highId ); | ||
when( store.getHighId() ).thenReturn( highId ); | ||
|
||
ReadRelationshipRecordsBackwardsStep step = new ReadRelationshipRecordsBackwardsStep( | ||
mock( StageControl.class ), Configuration.DEFAULT, store ); | ||
|
||
Object batch = step.nextBatchOrNull( 0, batchSize ); | ||
|
||
assertNotNull( batch ); | ||
|
||
RelationshipRecord[] records = (RelationshipRecord[]) batch; | ||
boolean hasRecordWithReservedId = Stream.of( records ).anyMatch( recordWithReservedId() ); | ||
assertFalse( "Batch contains record with reserved id " + Arrays.toString( records ), hasRecordWithReservedId ); | ||
} | ||
|
||
private static Predicate<RelationshipRecord> recordWithReservedId() | ||
{ | ||
return record -> record.getId() == IdGeneratorImpl.INTEGER_MINUS_ONE; | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...kernel/src/test/java/org/neo4j/unsafe/impl/batchimport/RelationshipLinkbackStageTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* 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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.unsafe.impl.batchimport; | ||
|
||
import org.junit.Test; | ||
|
||
import org.neo4j.graphdb.factory.GraphDatabaseSettings; | ||
import org.neo4j.kernel.impl.store.RelationshipStore; | ||
import org.neo4j.kernel.impl.store.id.IdGeneratorImpl; | ||
import org.neo4j.kernel.impl.store.record.RelationshipRecord; | ||
import org.neo4j.unsafe.impl.batchimport.cache.NodeRelationshipCache; | ||
import org.neo4j.unsafe.impl.batchimport.cache.NumberArrayFactory; | ||
import org.neo4j.unsafe.impl.batchimport.staging.ExecutionMonitors; | ||
import org.neo4j.unsafe.impl.batchimport.staging.ExecutionSupervisors; | ||
|
||
import static org.mockito.Mockito.never; | ||
import static org.mockito.Mockito.verify; | ||
|
||
public class RelationshipLinkbackStageTest | ||
{ | ||
@Test | ||
public void reservedIdIsSkipped() throws Exception | ||
{ | ||
long highId = 5; | ||
RelationshipStore store = StoreWithReservedId.newRelationshipStoreMock( highId ); | ||
RelationshipLinkbackStage stage = new RelationshipLinkbackStage( Configuration.DEFAULT, store, newCache() ); | ||
|
||
ExecutionSupervisors.superviseExecution( ExecutionMonitors.invisible(), Configuration.DEFAULT, stage ); | ||
|
||
verify( store, never() ).updateRecord( new RelationshipRecord( IdGeneratorImpl.INTEGER_MINUS_ONE ) ); | ||
} | ||
|
||
private static NodeRelationshipCache newCache() | ||
{ | ||
int denseNodeThreshold = Integer.parseInt( GraphDatabaseSettings.dense_node_threshold.getDefaultValue() ); | ||
return new NodeRelationshipCache( NumberArrayFactory.HEAP, denseNodeThreshold ); | ||
} | ||
} |
Oops, something went wrong.