@Override public long createNode( Map<String, Object> properties, Label... labels ) { return internalCreateNode( nodeStore.nextId(), properties, labels ); }
private long nextId( Class<?> clazz ) { NeoStores neoStores = ds.getDependencyResolver() .resolveDependency( RecordStorageEngine.class ).testAccessNeoStores(); if ( clazz.equals( PropertyKeyTokenRecord.class ) ) { return neoStores.getPropertyKeyTokenStore().nextId(); } if ( clazz.equals( RelationshipType.class ) ) { return neoStores.getRelationshipTypeTokenStore().nextId(); } if ( clazz.equals( Node.class ) ) { return neoStores.getNodeStore().nextId(); } if ( clazz.equals( Relationship.class ) ) { return neoStores.getRelationshipStore().nextId(); } throw new IllegalArgumentException( clazz.getName() ); }
for ( int i = 0; i < highestId; i++ ) assertThat( store.nextId(), is( (long) i ) ); record.setId( i ); store.updateRecord( record ); nextIds.add( store.nextId() ); // 2 nextIds.add( store.nextId() ); // 3 nextIds.add( store.nextId() ); // 5 nextIds.add( store.nextId() ); // 7 nextIds.add( store.nextId() ); // 51 assertThat( nextIds, contains( 2L, 3L, 5L, 7L, 50L ) ); store.close();
private long[] createRelationships( NeoStores neoStores, TransactionRecordState tx, long nodeId, int type, Direction direction, int count ) { long[] result = new long[count]; for ( int i = 0; i < count; i++ ) { long otherNodeId = neoStores.getNodeStore().nextId(); tx.nodeCreate( otherNodeId ); long first = direction == OUTGOING ? nodeId : otherNodeId; long other = direction == INCOMING ? nodeId : otherNodeId; long relId = neoStores.getRelationshipStore().nextId(); result[i] = relId; tx.relCreate( relId, type, first, other ); } return result; }
private TransactionToApply createNodeAndProperty( int progress ) throws Exception { TransactionState txState = new TxState(); long nodeId = nodeIds.nextId(); txState.nodeDoCreate( nodeId ); txState.nodeDoAddLabel( descriptor.getLabelId(), nodeId ); txState.nodeDoAddProperty( nodeId, descriptor.getPropertyId(), propertyValue( id, progress ) ); Collection<StorageCommand> commands = new ArrayList<>(); try ( StorageReader statement = storageEngine.newReader() ) { storageEngine.createCommands( commands, txState, statement, null, 0, NO_DECORATION ); } return tx( commands ); }
private TransactionRecordState nodeWithDynamicLabelRecord( NeoStores store, AtomicLong nodeId, AtomicLong dynamicLabelRecordId ) { TransactionRecordState recordState = newTransactionRecordState( store ); nodeId.set( store.getNodeStore().nextId() ); int[] labelIds = new int[20]; for ( int i = 0; i < labelIds.length; i++ ) { int labelId = (int) store.getLabelTokenStore().nextId(); recordState.createLabelToken( "Label" + i, labelId ); labelIds[i] = labelId; } recordState.nodeCreate( nodeId.get() ); for ( int labelId : labelIds ) { recordState.addLabelToNode( labelId, nodeId.get() ); } // Extract the dynamic label record id (which is also a verification that we allocated one) NodeRecord node = Iterables.single( recordChangeSet.getNodeRecords().changes() ).forReadingData(); dynamicLabelRecordId.set( Iterables.single( node.getDynamicLabelRecords() ).getId() ); return recordState; }
for ( int i = 0; i < highestId; i++ ) assertThat( store.nextId(), is( (long) i ) ); record.setId( i ); store.updateRecord( record ); nextIds.add( store.nextId() ); // recordsPerPage - 2 nextIds.add( store.nextId() ); // recordsPerPage - 1 nextIds.add( store.nextId() ); // recordsPerPage * 3 (we didn't use this id in the create-look above) assertThat( nextIds, contains( recordsPerPage - 2L, recordsPerPage - 1L, recordsPerPage * 3L ) ); store.close();
@Test public void shouldTellNodeInUse() throws Exception { // Given EphemeralFileSystemAbstraction fs = efs.get(); NodeStore store = newNodeStore( fs ); long exists = store.nextId(); store.updateRecord( new NodeRecord( exists, false, 10, 20, true ) ); long deleted = store.nextId(); store.updateRecord( new NodeRecord( deleted, false, 10, 20, true ) ); store.updateRecord( new NodeRecord( deleted, false, 10, 20, false ) ); // When & then assertTrue( store.isInUse( exists ) ); assertFalse( store.isInUse( deleted ) ); assertFalse( store.isInUse( nodeStore.recordFormat.getMaxId() ) ); }
@Test public void shouldMaintainCorrectDataWhenDeletingFromDenseNodeWithOneType() throws Exception { // GIVEN a node with a total of denseNodeThreshold-1 relationships NeoStores neoStores = neoStoresRule.builder() .with( GraphDatabaseSettings.dense_node_threshold.name(), "13" ).build(); TransactionRecordState tx = newTransactionRecordState( neoStores ); int nodeId = (int) neoStores.getNodeStore().nextId(); int typeA = 0; tx.nodeCreate( nodeId ); tx.createRelationshipTypeToken( "A", typeA ); long[] relationshipsCreated = createRelationships( neoStores, tx, nodeId, typeA, INCOMING, 15 ); //WHEN tx.relDelete( relationshipsCreated[0] ); // THEN the node should have been converted into a dense node assertDenseRelationshipCounts( recordChangeSet, nodeId, typeA, 0, 14 ); }
long nodeId = neoStores.getNodeStore().nextId(); long otherNode1Id = neoStores.getNodeStore().nextId(); long otherNode2Id = neoStores.getNodeStore().nextId(); TransactionRecordState recordState = newTransactionRecordState( neoStores ); recordState.nodeCreate( nodeId ); long otherNodeId = neoStores.getNodeStore().nextId(); recordState.nodeCreate( otherNodeId ); recordState.relCreate( neoStores.getRelationshipStore().nextId(), type5, nodeId, otherNodeId ); long otherNodeId = neoStores.getNodeStore().nextId(); recordState.nodeCreate( otherNodeId ); recordState.relCreate( neoStores.getRelationshipStore().nextId(), type15, nodeId, otherNodeId );
.with( GraphDatabaseSettings.dense_node_threshold.name(), "10" ).build(); TransactionRecordState tx = newTransactionRecordState( neoStores ); long nodeId = neoStores.getNodeStore().nextId();
@Test public void shouldConvertToDenseNodeRepresentationWhenHittingThresholdWithTheSameTypeSameDirection() throws Exception { // GIVEN a node with a total of denseNodeThreshold-1 relationships NeoStores neoStores = neoStoresRule.builder() .with( GraphDatabaseSettings.dense_node_threshold.name(), "8" ).build(); TransactionRecordState tx = newTransactionRecordState( neoStores ); long nodeId = neoStores.getNodeStore().nextId(); int typeA = 0; tx.nodeCreate( nodeId ); tx.createRelationshipTypeToken( "A", typeA ); createRelationships( neoStores, tx, nodeId, typeA, OUTGOING, 8 ); // here we're at the edge assertFalse( recordChangeSet.getNodeRecords().getOrLoad( nodeId, null ).forReadingData().isDense() ); // WHEN creating the relationship that pushes us over the threshold createRelationships( neoStores, tx, nodeId, typeA, OUTGOING, 1 ); // THEN the node should have been converted into a dense node assertTrue( recordChangeSet.getNodeRecords().getOrLoad( nodeId, null ).forReadingData().isDense() ); assertDenseRelationshipCounts( recordChangeSet, nodeId, typeA, 9, 0 ); }
@Test public void shouldConvertToDenseNodeRepresentationWhenHittingThresholdWithTheSameTypeDifferentDirection() throws Exception { // GIVEN a node with a total of denseNodeThreshold-1 relationships NeoStores neoStores = neoStoresRule.builder() .with( GraphDatabaseSettings.dense_node_threshold.name(), "49" ).build(); TransactionRecordState tx = newTransactionRecordState( neoStores ); long nodeId = neoStores.getNodeStore().nextId(); int typeA = 0; tx.nodeCreate( nodeId ); tx.createRelationshipTypeToken( "A", typeA ); createRelationships( neoStores, tx, nodeId, typeA, OUTGOING, 24 ); createRelationships( neoStores, tx, nodeId, typeA, INCOMING, 25 ); // here we're at the edge assertFalse( recordChangeSet.getNodeRecords().getOrLoad( nodeId, null ).forReadingData().isDense() ); // WHEN creating the relationship that pushes us over the threshold createRelationships( neoStores, tx, nodeId, typeA, INCOMING, 1 ); // THEN the node should have been converted into a dense node assertTrue( recordChangeSet.getNodeRecords().getOrLoad( nodeId, null ).forReadingData().isDense() ); assertDenseRelationshipCounts( recordChangeSet, nodeId, typeA, 24, 26 ); }
private Ids createNode( DataImporter.Monitor monitor, NeoStores neoStores, int propertyCount, int labelCount ) { PropertyStore propertyStore = neoStores.getPropertyStore(); RecordAccess<PropertyRecord,PrimitiveRecord> propertyRecordAccess = new DirectRecordAccess<>( propertyStore, new Loaders( neoStores ).propertyLoader() ); NodeStore nodeStore = neoStores.getNodeStore(); NodeRecord nodeRecord = nodeStore.newRecord(); nodeRecord.setId( nodeStore.nextId() ); nodeRecord.setInUse( true ); NodeLabelsField.parseLabelsField( nodeRecord ).put( labelIds( labelCount ), nodeStore, nodeStore.getDynamicLabelStore() ); long nextProp = new PropertyCreator( propertyStore, new PropertyTraverser() ) .createPropertyChain( nodeRecord, properties( propertyStore, propertyCount ), propertyRecordAccess ); nodeRecord.setNextProp( nextProp ); nodeStore.updateRecord( nodeRecord ); PropertyRecord[] propertyRecords = extractPropertyRecords( propertyRecordAccess, nextProp ); propertyRecordAccess.close(); monitor.nodesImported( 1 ); monitor.propertiesImported( propertyCount ); return new Ids( nodeRecord, propertyRecords ); }
@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() ); }
.with( GraphDatabaseSettings.dense_node_threshold.name(), "50" ).build(); TransactionRecordState tx = newTransactionRecordState( neoStores ); long nodeId = neoStores.getNodeStore().nextId(); int typeA = 0; int typeB = 1;
.with( GraphDatabaseSettings.dense_node_threshold.name(), "1" ).build(); TransactionRecordState tx = newTransactionRecordState( neoStores ); long nodeId = neoStores.getNodeStore().nextId(); int typeA = 0; int typeB = 12;
@Override public long createNode( Map<String, Object> properties, Label... labels ) { return internalCreateNode( nodeStore.nextId(), properties, labels ); }