@Test public void shouldApplyNodeCommandToTheStoreInRecoveryMode() throws Exception { // given final BatchTransactionApplier applier = newApplier( true ); final NodeRecord before = new NodeRecord( 11 ); before.setLabelField( 42, asList( one, two ) ); final NodeRecord after = new NodeRecord( 12 ); after.setInUse( true ); after.setLabelField( 42, asList( one, two, three ) ); final Command.NodeCommand command = new Command.NodeCommand( before, after ); // when boolean result = apply( applier, command::handle, transactionToApply ); // then assertFalse( result ); verify( lockService, times( 1 ) ).acquireNodeLock( command.getKey(), LockService.LockType.WRITE_LOCK ); verify( nodeStore, times( 1 ) ).setHighestPossibleIdInUse( after.getId() ); verify( nodeStore, times( 1 ) ).updateRecord( after ); verify( dynamicLabelStore, times( 1 ) ).setHighestPossibleIdInUse( three.getId() ); }
@Test public void shouldApplyNodeCommandToTheStoreAndInvalidateTheCache() throws Exception { // given final BatchTransactionApplier applier = newApplier( false ); final NodeRecord before = new NodeRecord( 11 ); before.setLabelField( 42, asList( one, two ) ); final NodeRecord after = new NodeRecord( 12 ); after.setInUse( false ); after.setLabelField( 42, asList( one, two, three ) ); final Command.NodeCommand command = new Command.NodeCommand( before, after ); // when boolean result = apply( applier, command::handle, transactionToApply ); // then assertFalse( result ); verify( lockService, times( 1 ) ).acquireNodeLock( command.getKey(), LockService.LockType.WRITE_LOCK ); verify( nodeStore, times( 1 ) ).updateRecord( after ); }
@Test public void shouldApplyNodeCommandToTheStore() throws Exception { // given final BatchTransactionApplier applier = newApplier( false ); final NodeRecord before = new NodeRecord( 11 ); before.setLabelField( 42, asList( one, two ) ); final NodeRecord after = new NodeRecord( 12 ); after.setInUse( true ); after.setLabelField( 42, asList( one, two, three ) ); final Command.NodeCommand command = new Command.NodeCommand( before, after ); // when boolean result = apply( applier, command::handle, transactionToApply ); // then assertFalse( result ); verify( lockService, times( 1 ) ).acquireNodeLock( command.getKey(), LockService.LockType.WRITE_LOCK ); verify( nodeStore, times( 1 ) ).updateRecord( after ); }
@Test public void shouldFreeSecondaryUnitIdOfShrunkRecord() throws Exception { // GIVEN EphemeralFileSystemAbstraction fs = efs.get(); nodeStore = newNodeStore( fs ); NodeRecord record = new NodeRecord( 5L ); record.setRequiresSecondaryUnit( true ); record.setSecondaryUnitId( 10L ); record.setInUse( true ); nodeStore.updateRecord( record ); nodeStore.setHighestPossibleIdInUse( 10L ); // WHEN record.setRequiresSecondaryUnit( false ); nodeStore.updateRecord( record ); // THEN IdGenerator idGenerator = idGeneratorFactory.get( IdType.NODE ); verify( idGenerator, never() ).freeId( 5L ); verify( idGenerator ).freeId( 10L ); }
@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 shouldFreeSecondaryUnitIdOfDeletedRecord() throws Exception { // GIVEN EphemeralFileSystemAbstraction fs = efs.get(); nodeStore = newNodeStore( fs ); NodeRecord record = new NodeRecord( 5L ); record.setRequiresSecondaryUnit( true ); record.setSecondaryUnitId( 10L ); record.setInUse( true ); nodeStore.updateRecord( record ); nodeStore.setHighestPossibleIdInUse( 10L ); // WHEN record.setInUse( false ); nodeStore.updateRecord( record ); // THEN IdGenerator idGenerator = idGeneratorFactory.get( IdType.NODE ); verify( idGenerator ).freeId( 5L ); verify( idGenerator ).freeId( 10L ); }
@Test public void shouldInvalidateTheCacheWhenTheNodeBecomesDense() throws Exception { // given final BatchTransactionApplier applier = newApplier( false ); final NodeRecord before = new NodeRecord( 11 ); before.setLabelField( 42, singletonList( one ) ); before.setInUse( true ); before.setDense( false ); final NodeRecord after = new NodeRecord( 12 ); after.setInUse( true ); after.setDense( true ); after.setLabelField( 42, asList( one, two, three ) ); final Command.NodeCommand command = new Command.NodeCommand( before, after ); // when boolean result = apply( applier, command::handle, transactionToApply ); // then assertFalse( result ); verify( lockService, times( 1 ) ).acquireNodeLock( command.getKey(), LockService.LockType.WRITE_LOCK ); verify( nodeStore, times( 1 ) ).updateRecord( after ); }
store.updateRecord( record ); store.updateRecord( record );
@Override public void endOfEntity() { // Make sure we have an ID if ( nodeRecord.getId() == NULL_REFERENCE.longValue() ) { nodeRecord.setId( nodeIds.next() ); } // Compose the labels if ( !hasLabelField ) { long[] labelIds = labelTokenRepository.getOrCreateIds( labels, labelsCursor ); InlineNodeLabels.putSorted( nodeRecord, labelIds, null, nodeStore.getDynamicLabelStore() ); } labelsCursor = 0; // Write data to stores nodeRecord.setNextProp( createAndWritePropertyChain() ); nodeRecord.setInUse( true ); nodeStore.updateRecord( nodeRecord ); nodeCount++; nodeRecord.clear(); nodeRecord.setId( NULL_REFERENCE.longValue() ); hasLabelField = false; super.endOfEntity(); }
store.updateRecord( record ); store.updateRecord( record );
@Test public void shouldCombineProperFiveByteLabelField() throws Exception { // GIVEN // -- a store EphemeralFileSystemAbstraction fs = efs.get(); nodeStore = newNodeStore( fs ); // -- a record with the msb carrying a negative value long nodeId = 0; long labels = 0x8000000001L; NodeRecord record = new NodeRecord( nodeId, false, NO_NEXT_RELATIONSHIP.intValue(), NO_NEXT_PROPERTY.intValue() ); record.setInUse( true ); record.setLabelField( labels, Collections.emptyList() ); nodeStore.updateRecord( record ); // WHEN // -- reading that record back NodeRecord readRecord = nodeStore.getRecord( nodeId, nodeStore.newRecord(), NORMAL ); // THEN // -- the label field must be the same assertEquals( labels, readRecord.getLabelField() ); }
nodeStore.updateRecord( nodeRecord ); nodesRemoved++;
@Test public void shouldContainFedNodeUpdate() throws Exception { OnlineIndexUpdates onlineIndexUpdates = new OnlineIndexUpdates( nodeStore, relationshipStore, indexingService, propertyPhysicalToLogicalConverter ); int nodeId = 0; NodeRecord inUse = getNode( nodeId, true ); Value propertyValue = Values.of( "hej" ); long propertyId = createNodeProperty( inUse, propertyValue, 1 ); NodeRecord notInUse = getNode( nodeId, false ); nodeStore.updateRecord( inUse ); Command.NodeCommand nodeCommand = new Command.NodeCommand( inUse, notInUse ); PropertyRecord propertyBlocks = new PropertyRecord( propertyId ); propertyBlocks.setNodeId( nodeId ); Command.PropertyCommand propertyCommand = new Command.PropertyCommand( recordAccess.getIfLoaded( propertyId ).forReadingData(), propertyBlocks ); StoreIndexDescriptor indexDescriptor = forSchema( multiToken( ENTITY_TOKENS, NODE, 1, 4, 6 ), EMPTY.getProviderDescriptor() ).withId( 0 ); indexingService.createIndexes( indexDescriptor ); indexingService.getIndexProxy( indexDescriptor.schema() ).awaitStoreScanCompleted(); onlineIndexUpdates.feed( LongObjectMaps.immutable.of( nodeId, singletonList( propertyCommand ) ), LongObjectMaps.immutable.empty(), LongObjectMaps.immutable.of( nodeId, nodeCommand ), LongObjectMaps.immutable.empty() ); assertTrue( onlineIndexUpdates.hasUpdates() ); Iterator<IndexEntryUpdate<SchemaDescriptor>> iterator = onlineIndexUpdates.iterator(); assertEquals( iterator.next(), IndexEntryUpdate.remove( nodeId, indexDescriptor, propertyValue, null, null ) ); assertFalse( iterator.hasNext() ); }
nodeStore.updateRecord( record ); nodeId = nodeStore.nextId();
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 ); }
long propId = record.getNextProp(); record.setNextProp( AbstractBaseRecord.NO_ID ); stores.getNodeStore().updateRecord( record ); PropertyRecord propRecord = stores.getPropertyStore().getRecord( propId, stores.getPropertyStore().newRecord(), RecordLoad.NORMAL ); propRecord.setInUse( false );
long nodePropertyId = createNodeProperty( inUseNode, nodePropertyValue, 1 ); NodeRecord notInUseNode = getNode( nodeId, false ); nodeStore.updateRecord( inUseNode );
@Override public void endOfEntity() { // Make sure we have an ID if ( nodeRecord.getId() == NULL_REFERENCE.longValue() ) { nodeRecord.setId( nodeIds.next() ); } // Compose the labels if ( !hasLabelField ) { long[] labelIds = labelTokenRepository.getOrCreateIds( labels, labelsCursor ); InlineNodeLabels.putSorted( nodeRecord, labelIds, null, nodeStore.getDynamicLabelStore() ); } labelsCursor = 0; // Write data to stores nodeRecord.setNextProp( createAndWritePropertyChain() ); nodeRecord.setInUse( true ); nodeStore.updateRecord( nodeRecord ); nodeCount++; nodeRecord.clear(); nodeRecord.setId( NULL_REFERENCE.longValue() ); hasLabelField = false; super.endOfEntity(); }
nodeStore.updateRecord( nodeRecord ); nodesRemoved++;