From 737d1770cb9177d8735d185095f8bc163a718b37 Mon Sep 17 00:00:00 2001 From: Anton Persson Date: Tue, 25 Jul 2017 11:37:10 +0200 Subject: [PATCH] General cleanup --- .../consistency/ConsistencyCheckService.java | 4 +- .../storeview/LabelScanViewIdIterator.java | 4 -- .../internal/BatchInserterImpl.java | 6 -- .../graphdb/NativeLabelScanStoreUpdateIT.java | 29 ++++---- .../batchinsert/internal/BatchInsertTest.java | 72 +++++++++---------- 5 files changed, 50 insertions(+), 65 deletions(-) diff --git a/community/consistency-check/src/main/java/org/neo4j/consistency/ConsistencyCheckService.java b/community/consistency-check/src/main/java/org/neo4j/consistency/ConsistencyCheckService.java index e5f3f2d18ce9a..62aeb4602fb66 100644 --- a/community/consistency-check/src/main/java/org/neo4j/consistency/ConsistencyCheckService.java +++ b/community/consistency-check/src/main/java/org/neo4j/consistency/ConsistencyCheckService.java @@ -229,8 +229,8 @@ public Result runFullConsistencyCheck( final File storeDir, Config config, Progr try ( NeoStores neoStores = factory.openAllNeoStores() ) { life.start(); - SchemaIndexProvider indexes = new LuceneSchemaIndexProvider( fileSystem, DirectoryFactory.PERSISTENT, - storeDir, logProvider, config, operationalMode ); + SchemaIndexProvider indexes = life.add( new LuceneSchemaIndexProvider( fileSystem, DirectoryFactory.PERSISTENT, + storeDir, logProvider, config, operationalMode ) ); LabelScanStore labelScanStore = new NativeLabelScanStore( pageCache, storeDir, FullStoreChangeStream.EMPTY, true, new Monitors(), diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/state/storeview/LabelScanViewIdIterator.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/state/storeview/LabelScanViewIdIterator.java index 731a07542a75b..9cfe7244b9845 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/state/storeview/LabelScanViewIdIterator.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/state/storeview/LabelScanViewIdIterator.java @@ -25,10 +25,6 @@ /** * Node id iterator used during index population when we go over node ids indexed in label scan store. - * Before each iteration check if data in current reader can be expired because of concurrent updates that came from - * other transactions. - * In that case will reopen corresponding lucene reader and will reposition itself into the same position of matched - * node ids. */ class LabelScanViewIdIterator implements PrimitiveLongResourceIterator { diff --git a/community/kernel/src/main/java/org/neo4j/unsafe/batchinsert/internal/BatchInserterImpl.java b/community/kernel/src/main/java/org/neo4j/unsafe/batchinsert/internal/BatchInserterImpl.java index ed0543f41b970..c299859208d20 100644 --- a/community/kernel/src/main/java/org/neo4j/unsafe/batchinsert/internal/BatchInserterImpl.java +++ b/community/kernel/src/main/java/org/neo4j/unsafe/batchinsert/internal/BatchInserterImpl.java @@ -1134,12 +1134,6 @@ NeoStores getNeoStores() return neoStores; } - // test-access - LabelScanStore getLabelScanStore() - { - return labelScanStore; - } - void forceFlushChanges() { flushStrategy.forceFlush(); diff --git a/community/kernel/src/test/java/org/neo4j/graphdb/NativeLabelScanStoreUpdateIT.java b/community/kernel/src/test/java/org/neo4j/graphdb/NativeLabelScanStoreUpdateIT.java index d3fb7cf8ce8ac..6b8fc4dec54fa 100644 --- a/community/kernel/src/test/java/org/neo4j/graphdb/NativeLabelScanStoreUpdateIT.java +++ b/community/kernel/src/test/java/org/neo4j/graphdb/NativeLabelScanStoreUpdateIT.java @@ -176,7 +176,7 @@ public void retrieveNodeIdsInAscendingOrder() public void shouldHandleLargeAmountsOfNodesAddedAndRemovedInSameTx() throws Exception { // Given - GraphDatabaseService db = db(); + GraphDatabaseService db = dbRule; int labelsToAdd = 80; int labelsToRemove = 40; @@ -214,16 +214,11 @@ public void shouldHandleLargeAmountsOfNodesAddedAndRemovedInSameTx() throws Exce } } - protected GraphDatabaseService db() - { - return dbRule; - } - private void verifyFoundNodes( Label label, String sizeMismatchMessage, long... expectedNodeIds ) { - try ( Transaction ignored = db().beginTx() ) + try ( Transaction ignored = dbRule.beginTx() ) { - ResourceIterator nodes = db().findNodes( label ); + ResourceIterator nodes = dbRule.findNodes( label ); List nodeList = Iterators.asList( nodes ); assertThat( sizeMismatchMessage, nodeList, Matchers.hasSize( expectedNodeIds.length ) ); int index = 0; @@ -236,7 +231,7 @@ private void verifyFoundNodes( Label label, String sizeMismatchMessage, long... private void removeLabels( Node node, Label... labels ) { - try ( Transaction tx = db().beginTx() ) + try ( Transaction tx = dbRule.beginTx() ) { for ( Label label : labels ) { @@ -248,7 +243,7 @@ private void removeLabels( Node node, Label... labels ) private void deleteNode( Node node ) { - try ( Transaction tx = db().beginTx() ) + try ( Transaction tx = dbRule.beginTx() ) { node.delete(); tx.success(); @@ -257,17 +252,17 @@ private void deleteNode( Node node ) private Set getAllNodesWithLabel( Label label ) { - try ( Transaction ignored = db().beginTx() ) + try ( Transaction ignored = dbRule.beginTx() ) { - return asSet( db().findNodes( label ) ); + return asSet( dbRule.findNodes( label ) ); } } private Node createLabeledNode( Label... labels ) { - try ( Transaction tx = db().beginTx() ) + try ( Transaction tx = dbRule.beginTx() ) { - Node node = db().createNode( labels ); + Node node = dbRule.createNode( labels ); tx.success(); return node; } @@ -275,7 +270,7 @@ private Node createLabeledNode( Label... labels ) private void addLabels( Node node, Label... labels ) { - try ( Transaction tx = db().beginTx() ) + try ( Transaction tx = dbRule.beginTx() ) { for ( Label label : labels ) { @@ -287,9 +282,9 @@ private void addLabels( Node node, Label... labels ) private Node getNodeById( long id ) { - try ( Transaction ignored = db().beginTx() ) + try ( Transaction ignored = dbRule.beginTx() ) { - return db().getNodeById( id ); + return dbRule.getNodeById( id ); } } diff --git a/community/kernel/src/test/java/org/neo4j/unsafe/batchinsert/internal/BatchInsertTest.java b/community/kernel/src/test/java/org/neo4j/unsafe/batchinsert/internal/BatchInsertTest.java index 70af912ef6adb..b141435997894 100644 --- a/community/kernel/src/test/java/org/neo4j/unsafe/batchinsert/internal/BatchInsertTest.java +++ b/community/kernel/src/test/java/org/neo4j/unsafe/batchinsert/internal/BatchInsertTest.java @@ -102,6 +102,7 @@ import static java.lang.Integer.parseInt; import static java.lang.String.format; +import static java.util.Collections.singletonList; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.Matchers.arrayContaining; import static org.hamcrest.Matchers.emptyArray; @@ -236,7 +237,7 @@ private BatchInserter newBatchInserter() throws Exception private BatchInserter newBatchInserterWithSchemaIndexProvider( KernelExtensionFactory provider ) throws Exception { - return BatchInserters.inserter( storeDir.absolutePath(), fileSystemRule.get(), configuration(), Arrays.asList( provider ) ); + return BatchInserters.inserter( storeDir.absolutePath(), fileSystemRule.get(), configuration(), singletonList( provider ) ); } private GraphDatabaseService switchToEmbeddedGraphDatabaseService( BatchInserter inserter ) @@ -653,7 +654,7 @@ public void createEntitiesWithDynamicPropertiesMap() throws Exception BatchInserter inserter = globalInserter; setAndGet( inserter, "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" ); - setAndGet( inserter, intArray( 20 ) ); + setAndGet( inserter, intArray() ); } @Test @@ -1035,32 +1036,6 @@ public void shouldPopulateLabelScanStoreOnShutdown() throws Exception labelScanStore.shutdown(); } - private LabelScanStore getLabelScanStore() - { - return new NativeLabelScanStore( pageCacheRule.getPageCache( fileSystemRule.get() ), storeDir.absolutePath(), - FullStoreChangeStream.EMPTY, true, new Monitors(), RecoveryCleanupWorkCollector.IMMEDIATE ); - } - - private void assertLabelScanStoreContains( LabelScanStore labelScanStore, int labelId, long... nodes ) - { - try ( LabelScanReader labelScanReader = labelScanStore.newReader() ) - { - List actualNodeIds = extractPrimitiveLongIteratorAsList( labelScanReader.nodesWithLabel( labelId ) ); - List expectedNodeIds = Arrays.stream( nodes ).boxed().collect( Collectors.toList() ); - assertEquals( expectedNodeIds, actualNodeIds ); - } - } - - private List extractPrimitiveLongIteratorAsList( PrimitiveLongIterator primitiveLongIterator ) - { - List actualNodeIds = new ArrayList<>(); - while ( primitiveLongIterator.hasNext() ) - { - actualNodeIds.add( primitiveLongIterator.next() ); - } - return actualNodeIds; - } - @Test public void propertiesCanBeReSetUsingBatchInserter() throws Exception { @@ -1092,7 +1067,6 @@ public void propertiesCanBeReSetUsingBatchInserter() throws Exception * During first update email property will be migrated to dynamic property and last property record will become * empty. That record should be deleted form property chain or otherwise on next node load user will get an * property record not in use exception. - * @throws Exception */ @Test public void testCleanupEmptyPropertyRecords() throws Exception @@ -1192,8 +1166,8 @@ public void shouldGetRelationships() throws Exception // GIVEN BatchInserter inserter = globalInserter; long node = inserter.createNode( null ); - createRelationships( inserter, node, RelTypes.REL_TYPE1, 3, 2, 1 ); - createRelationships( inserter, node, RelTypes.REL_TYPE2, 4, 5, 6 ); + createRelationships( inserter, node, RelTypes.REL_TYPE1, 3 ); + createRelationships( inserter, node, RelTypes.REL_TYPE2, 4 ); // WHEN Set gottenRelationships = Iterables.asSet( inserter.getRelationshipIds( node ) ); @@ -1412,7 +1386,7 @@ public void shouldIgnoreRemovingNonExistentNodeProperty() throws Exception { // given BatchInserter inserter = globalInserter; - long id = inserter.createNode( Collections.emptyMap() ); + long id = inserter.createNode( Collections.emptyMap() ); // when inserter.removeNodeProperty( id, "non-existent" ); @@ -1425,7 +1399,7 @@ public void shouldIgnoreRemovingNonExistentRelationshipProperty() throws Excepti { // given BatchInserter inserter = globalInserter; - Map noProperties = Collections.emptyMap(); + Map noProperties = Collections.emptyMap(); long nodeId1 = inserter.createNode( noProperties ); long nodeId2 = inserter.createNode( noProperties ); long id = inserter.createRelationship( nodeId1, nodeId2, MyRelTypes.TEST, noProperties ); @@ -1436,8 +1410,33 @@ public void shouldIgnoreRemovingNonExistentRelationshipProperty() throws Excepti // then no exception should be thrown, this mimics GraphDatabaseService behaviour } - private void createRelationships( BatchInserter inserter, long node, RelationshipType relType, - int out, int in, int loop ) + private LabelScanStore getLabelScanStore() + { + return new NativeLabelScanStore( pageCacheRule.getPageCache( fileSystemRule.get() ), storeDir.absolutePath(), + FullStoreChangeStream.EMPTY, true, new Monitors(), RecoveryCleanupWorkCollector.IMMEDIATE ); + } + + private void assertLabelScanStoreContains( LabelScanStore labelScanStore, int labelId, long... nodes ) + { + try ( LabelScanReader labelScanReader = labelScanStore.newReader() ) + { + List actualNodeIds = extractPrimitiveLongIteratorAsList( labelScanReader.nodesWithLabel( labelId ) ); + List expectedNodeIds = Arrays.stream( nodes ).boxed().collect( Collectors.toList() ); + assertEquals( expectedNodeIds, actualNodeIds ); + } + } + + private List extractPrimitiveLongIteratorAsList( PrimitiveLongIterator primitiveLongIterator ) + { + List actualNodeIds = new ArrayList<>(); + while ( primitiveLongIterator.hasNext() ) + { + actualNodeIds.add( primitiveLongIterator.next() ); + } + return actualNodeIds; + } + + private void createRelationships( BatchInserter inserter, long node, RelationshipType relType, int out ) { for ( int i = 0; i < out; i++ ) { @@ -1478,8 +1477,9 @@ private void setAndGet( BatchInserter inserter, Object value ) assertEquals( Values.of( value ), readValue ); } - private int[] intArray( int length ) + private int[] intArray() { + int length = 20; int[] array = new int[length]; for ( int i = 0, startValue = (int)Math.pow( 2, 30 ); i < length; i++ ) {