@Override public long createRelationship( long node1, long node2, RelationshipType type, Map<String, Object> properties ) { long id = relationshipStore.nextId(); int typeId = getOrCreateRelationshipTypeId( type.name() ); relationshipCreator.relationshipCreate( id, typeId, node1, node2, recordAccess, noopLockClient ); if ( properties != null && !properties.isEmpty() ) { RelationshipRecord record = recordAccess.getRelRecords().getOrLoad( id, null ).forChangingData(); record.setNextProp( propertyCreator.createPropertyChain( record, propertiesIterator( properties ), recordAccess.getPropertyRecords() ) ); } flushStrategy.flush(); return id; }
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() ); }
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; }
recordState.nodeCreate( otherNode1Id ); recordState.nodeCreate( otherNode2Id ); recordState.relCreate( neoStores.getRelationshipStore().nextId(), type10, nodeId, otherNode1Id ); recordState.relCreate( neoStores.getRelationshipStore().nextId(), type10, nodeId, otherNode2Id ); long otherNodeId = neoStores.getNodeStore().nextId(); recordState.nodeCreate( otherNodeId ); recordState.relCreate( neoStores.getRelationshipStore().nextId(), type5, nodeId, otherNodeId ); BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier( neoStores, mock( CacheAccessBackDoor.class ), LockService.NO_LOCK_SERVICE ); long otherNodeId = neoStores.getNodeStore().nextId(); recordState.nodeCreate( otherNodeId ); recordState.relCreate( neoStores.getRelationshipStore().nextId(), type15, nodeId, otherNodeId ); BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier( neoStores, mock( CacheAccessBackDoor.class ), LockService.NO_LOCK_SERVICE );
@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() ); }
@Test public void shouldDeleteIdGeneratorsWhenOpeningExistingStore() throws IOException { // given long expectedHighId; try ( BatchingNeoStores stores = BatchingNeoStores.batchingNeoStoresWithExternalPageCache( storage.fileSystem(), storage.pageCache(), PageCacheTracer.NULL, storage.directory().absolutePath(), LATEST_RECORD_FORMATS, DEFAULT, NullLogService.getInstance(), EMPTY, Config.defaults() ) ) { stores.createNew(); RelationshipStore relationshipStore = stores.getRelationshipStore(); RelationshipRecord record = relationshipStore.newRecord(); long no = NULL_REFERENCE.longValue(); record.initialize( true, no, 1, 2, 0, no, no, no, no, true, true ); record.setId( relationshipStore.nextId() ); expectedHighId = relationshipStore.getHighId(); relationshipStore.updateRecord( record ); // fiddle with the highId relationshipStore.setHighId( record.getId() + 999 ); } // when try ( BatchingNeoStores stores = BatchingNeoStores.batchingNeoStoresWithExternalPageCache( storage.fileSystem(), storage.pageCache(), PageCacheTracer.NULL, storage.directory().absolutePath(), LATEST_RECORD_FORMATS, DEFAULT, NullLogService.getInstance(), EMPTY, Config.defaults() ) ) { stores.pruneAndOpenExistingStore( Predicates.alwaysTrue(), Predicates.alwaysTrue() ); // then assertEquals( expectedHighId, stores.getRelationshipStore().getHighId() ); } }
@Override public long createRelationship( long node1, long node2, RelationshipType type, Map<String, Object> properties ) { long id = relationshipStore.nextId(); int typeId = getOrCreateRelationshipTypeId( type.name() ); relationshipCreator.relationshipCreate( id, typeId, node1, node2, recordAccess, noopLockClient ); if ( properties != null && !properties.isEmpty() ) { RelationshipRecord record = recordAccess.getRelRecords().getOrLoad( id, null ).forChangingData(); record.setNextProp( propertyCreator.createPropertyChain( record, propertiesIterator( properties ), recordAccess.getPropertyRecords() ) ); } flushStrategy.flush(); return id; }