private RecordProxy<NodeRecord,Void> getNodeRecord( long id ) { if ( id < 0 || id >= nodeStore.getHighId() ) { throw new NotFoundException( "id=" + id ); } return recordAccess.getNodeRecords().getOrLoad( id, null ); }
@Override public void createNode( long id, Map<String, Object> properties, Label... labels ) { IdValidator.assertValidId( IdType.NODE, id, maxNodeId ); if ( nodeStore.isInUse( id ) ) { throw new IllegalArgumentException( "id=" + id + " already in use" ); } long highId = nodeStore.getHighId(); if ( highId <= id ) { nodeStore.setHighestPossibleIdInUse( id ); } internalCreateNode( id, properties, labels ); }
private static ExecutionMonitor migrationBatchImporterMonitor( NeoStores legacyStore, final ProgressReporter progressReporter, Configuration config ) { return new BatchImporterProgressMonitor( legacyStore.getNodeStore().getHighId(), legacyStore.getRelationshipStore().getHighId(), config, progressReporter ); }
/** * Optimizes the relationship groups store by physically locating groups for each node together. */ public void defragmentRelationshipGroups() { // Defragment relationships groups for better performance new RelationshipGroupDefragmenter( config, executionMonitor, RelationshipGroupDefragmenter.Monitor.EMPTY, numberArrayFactory ) .run( max( maxMemory, peakMemoryUsage ), neoStore, neoStore.getNodeStore().getHighId() ); }
@Test void scanForHighIdOnlyOnceWhenProcessCache() { NeoStores neoStores = mock( NeoStores.class, Mockito.RETURNS_MOCKS ); NodeStore nodeStore = mock( NodeStore.class ); NodeRecord nodeRecord = mock( NodeRecord.class ); StoreProcessor storeProcessor = mock( StoreProcessor.class ); when( neoStores.getNodeStore() ).thenReturn( nodeStore ); when( nodeStore.getHighId() ).thenReturn( 10L ); when( nodeStore.getRecord( anyLong(), any( NodeRecord.class ), any( RecordLoad.class ) ) ).thenReturn( nodeRecord ); when( nodeStore.newRecord() ).thenReturn( nodeRecord ); StoreAccess storeAccess = new StoreAccess( neoStores ); storeAccess.initialize(); CacheTask.CheckNextRel cacheTask = new CacheTask.CheckNextRel( Stage.SEQUENTIAL_FORWARD, new DefaultCacheAccess( Counts.NONE, 1 ), storeAccess, storeProcessor ); cacheTask.processCache(); verify( nodeStore, times( 1 ) ).getHighId(); } }
@Test public void shouldBeAbleToForceStoreScan() throws Exception { when( labelScanStore.newReader() ).thenThrow( new RuntimeException( "Should not be used" ) ); when( nodeStore.getHighestPossibleIdInUse() ).thenReturn( 200L ); when( nodeStore.getHighId() ).thenReturn( 20L ); when( nodeStore.openPageCursorForReading( anyLong() ) ).thenReturn( mock( PageCursor.class ) ); mockLabelNodeCount( countStore, 2 ); mockLabelNodeCount( countStore, 6 ); DynamicIndexStoreView storeView = dynamicIndexStoreView(); StoreScan<Exception> storeScan = storeView .visitNodes( new int[]{2, 6}, propertyKeyIdFilter, propertyUpdateVisitor, labelUpdateVisitor, true ); storeScan.run(); Mockito.verify( nodeStore, times( 1 ) ) .getRecordByCursor( anyLong(), any( NodeRecord.class ), any( RecordLoad.class ), any( PageCursor.class ) ); Mockito.verify( nodeStore, times( 200 ) ) .nextRecordByCursor( any( NodeRecord.class ), any( RecordLoad.class ), any( PageCursor.class ) ); }
@Test public void visitOnlyLabeledNodes() throws Exception { LabelScanReader labelScanReader = mock( LabelScanReader.class ); when( labelScanStore.newReader() ).thenReturn( labelScanReader ); when( nodeLabelRanges.maxCount() ).thenReturn( 1L ); PrimitiveLongResourceIterator labeledNodesIterator = PrimitiveLongResourceCollections.iterator( null, 1, 2, 3, 4, 5, 6, 7, 8 ); when( nodeStore.getHighestPossibleIdInUse() ).thenReturn( 200L ); when( nodeStore.getHighId() ).thenReturn( 20L ); when( labelScanReader.nodesWithAnyOfLabels( new int[] {2, 6} ) ).thenReturn( labeledNodesIterator ); when( nodeStore.openPageCursorForReading( anyLong() ) ).thenReturn( mock( PageCursor.class ) ); mockLabelNodeCount( countStore, 2 ); mockLabelNodeCount( countStore, 6 ); DynamicIndexStoreView storeView = dynamicIndexStoreView(); StoreScan<Exception> storeScan = storeView .visitNodes( new int[]{2, 6}, propertyKeyIdFilter, propertyUpdateVisitor, labelUpdateVisitor, false ); storeScan.run(); Mockito.verify( nodeStore, times( 8 ) ) .getRecordByCursor( anyLong(), any( NodeRecord.class ), any( RecordLoad.class ), any( PageCursor.class ) ); }
@Test public void iterateOverLabeledNodeIds() { PrimitiveLongResourceIterator labeledNodes = PrimitiveLongResourceCollections.iterator( null, 1, 2, 4, 8 ); when( nodeStore.getHighId() ).thenReturn( 15L ); int[] labelIds = new int[]{1, 2}; when( labelScanReader.nodesWithAnyOfLabels( labelIds ) ).thenReturn( labeledNodes ); LabelScanViewNodeStoreScan<Exception> storeScan = getLabelScanViewStoreScan( labelIds ); PrimitiveLongResourceIterator idIterator = storeScan.getEntityIdIterator(); List<Long> visitedNodeIds = PrimitiveLongCollections.asList( idIterator ); assertThat(visitedNodeIds, Matchers.hasSize( 4 )); assertThat( visitedNodeIds, Matchers.hasItems( 1L, 2L, 4L, 8L ) ); }
private boolean databaseExistsAndContainsData() { File metaDataFile = databaseLayout.metadataStore(); try ( PagedFile pagedFile = pageCache.map( metaDataFile, pageCache.pageSize(), StandardOpenOption.READ ) ) { // OK so the db probably exists } catch ( IOException e ) { // It's OK return false; } try ( NeoStores stores = newStoreFactory( databaseLayout ).openNeoStores( StoreType.NODE, StoreType.RELATIONSHIP ) ) { return stores.getNodeStore().getHighId() > 0 || stores.getRelationshipStore().getHighId() > 0; } }
/** * Populates {@link NodeRelationshipCache} with node degrees, which is required to know how to physically layout each * relationship chain. This is required before running {@link #linkRelationships(int)}. */ public void calculateNodeDegrees() { Configuration relationshipConfig = configWithRecordsPerPageBasedBatchSize( config, neoStore.getRelationshipStore() ); nodeRelationshipCache.setNodeCount( neoStore.getNodeStore().getHighId() ); MemoryUsageStatsProvider memoryUsageStats = new MemoryUsageStatsProvider( neoStore, nodeRelationshipCache ); NodeDegreeCountStage nodeDegreeStage = new NodeDegreeCountStage( relationshipConfig, neoStore.getRelationshipStore(), nodeRelationshipCache, memoryUsageStats ); executeStage( nodeDegreeStage ); nodeRelationshipCache.countingCompleted(); availableMemoryForLinking = maxMemory - totalMemoryUsageOf( nodeRelationshipCache, neoStore ); }
when( nodeStore.getHighId() ).thenReturn( total ); NodeRecord emptyRecord = new NodeRecord( 0 ); NodeRecord inUseRecord = new NodeRecord( 42 );
@Test public void shouldSetCorrectHighIdWhenApplyingExternalTransactions() throws Exception { // WHEN recovering a transaction that creates some data long nodeId = neoStores.getNodeStore().nextId(); long relationshipId = neoStores.getRelationshipStore().nextId(); int type = 1; applyExternalTransaction( 1, new NodeCommand( new NodeRecord( nodeId ), inUse( created( new NodeRecord( nodeId ) ) ) ), new RelationshipCommand( null, inUse( created( with( new RelationshipRecord( relationshipId ), nodeId, nodeId, type ) ) ) ) ); // and when, later on, recovering a transaction deleting some of those applyExternalTransaction( 2, new NodeCommand( inUse( created( new NodeRecord( nodeId ) ) ), new NodeRecord( nodeId ) ), new RelationshipCommand( null, new RelationshipRecord( relationshipId ) ) ); // THEN that should be possible and the high ids should be correct, i.e. highest applied + 1 assertEquals( nodeId + 1, neoStores.getNodeStore().getHighId() ); assertEquals( relationshipId + 1, neoStores.getRelationshipStore().getHighId() ); }
assertEquals( node.getSecondaryUnitId() + 1, neoStores.getNodeStore().getHighId() ); assertEquals( relationship.getSecondaryUnitId() + 1, neoStores.getRelationshipStore().getHighId() ); assertEquals( relationshipGroup.getSecondaryUnitId() + 1, neoStores.getRelationshipGroupStore().getHighId() );
assertEquals( "NodeStore", 20 + 1, neoStores.getNodeStore().getHighId() ); assertEquals( "DynamicNodeLabelStore", 5 + 1, neoStores.getNodeStore().getDynamicLabelStore().getHighId() ); assertEquals( "RelationshipStore", 45 + 1, neoStores.getRelationshipStore().getHighId() );
private RecordProxy<NodeRecord,Void> getNodeRecord( long id ) { if ( id < 0 || id >= nodeStore.getHighId() ) { throw new NotFoundException( "id=" + id ); } return recordAccess.getNodeRecords().getOrLoad( id, null ); }
@Override public void createNode( long id, Map<String, Object> properties, Label... labels ) { IdValidator.assertValidId( IdType.NODE, id, maxNodeId ); if ( nodeStore.isInUse( id ) ) { throw new IllegalArgumentException( "id=" + id + " already in use" ); } long highId = nodeStore.getHighId(); if ( highId <= id ) { nodeStore.setHighestPossibleIdInUse( id ); } internalCreateNode( id, properties, labels ); }
private static ExecutionMonitor migrationBatchImporterMonitor( NeoStores legacyStore, final ProgressReporter progressReporter, Configuration config ) { return new BatchImporterProgressMonitor( legacyStore.getNodeStore().getHighId(), legacyStore.getRelationshipStore().getHighId(), config, progressReporter ); }
/** * Optimizes the relationship groups store by physically locating groups for each node together. */ public void defragmentRelationshipGroups() { // Defragment relationships groups for better performance new RelationshipGroupDefragmenter( config, executionMonitor, RelationshipGroupDefragmenter.Monitor.EMPTY, numberArrayFactory ) .run( max( maxMemory, peakMemoryUsage ), neoStore, neoStore.getNodeStore().getHighId() ); }
private boolean databaseExistsAndContainsData() { File metaDataFile = databaseLayout.metadataStore(); try ( PagedFile pagedFile = pageCache.map( metaDataFile, pageCache.pageSize(), StandardOpenOption.READ ) ) { // OK so the db probably exists } catch ( IOException e ) { // It's OK return false; } try ( NeoStores stores = newStoreFactory( databaseLayout ).openNeoStores( StoreType.NODE, StoreType.RELATIONSHIP ) ) { return stores.getNodeStore().getHighId() > 0 || stores.getRelationshipStore().getHighId() > 0; } }
/** * Populates {@link NodeRelationshipCache} with node degrees, which is required to know how to physically layout each * relationship chain. This is required before running {@link #linkRelationships(int)}. */ public void calculateNodeDegrees() { Configuration relationshipConfig = configWithRecordsPerPageBasedBatchSize( config, neoStore.getRelationshipStore() ); nodeRelationshipCache.setNodeCount( neoStore.getNodeStore().getHighId() ); MemoryUsageStatsProvider memoryUsageStats = new MemoryUsageStatsProvider( neoStore, nodeRelationshipCache ); NodeDegreeCountStage nodeDegreeStage = new NodeDegreeCountStage( relationshipConfig, neoStore.getRelationshipStore(), nodeRelationshipCache, memoryUsageStats ); executeStage( nodeDegreeStage ); nodeRelationshipCache.countingCompleted(); availableMemoryForLinking = maxMemory - totalMemoryUsageOf( nodeRelationshipCache, neoStore ); }