@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 ); }
@Override public boolean visitNodeCommand( Command.NodeCommand command ) { // for label store updates NodeRecord before = command.getBefore(); NodeRecord after = command.getAfter(); NodeLabels labelFieldBefore = parseLabelsField( before ); NodeLabels labelFieldAfter = parseLabelsField( after ); if ( !(labelFieldBefore.isInlined() && labelFieldAfter.isInlined() && before.getLabelField() == after.getLabelField()) ) { long[] labelsBefore = labelFieldBefore.getIfLoaded(); long[] labelsAfter = labelFieldAfter.getIfLoaded(); if ( labelsBefore != null && labelsAfter != null ) { if ( labelUpdates == null ) { labelUpdates = new ArrayList<>(); } labelUpdates.add( NodeLabelUpdate.labelChanges( command.getKey(), labelsBefore, labelsAfter, txId ) ); } } // for indexes return indexUpdatesExtractor.visitNodeCommand( command ); }
@Override public boolean visitNodeCommand( NodeCommand command ) { nodeCommandsById.put( command.getKey(), command ); if ( !hasUpdates && mayResultInIndexUpdates( command ) ) { hasUpdates = true; } return false; }
@Override public boolean visitNodeCommand( Command.NodeCommand command ) { // acquire lock lockGroup.add( lockService.acquireNodeLock( command.getKey(), LockService.LockType.WRITE_LOCK ) ); // update store updateStore( neoStores.getNodeStore(), command ); return false; }
@Override public boolean visitNodeCommand( Command.NodeCommand command ) { // for label store updates NodeRecord before = command.getBefore(); NodeRecord after = command.getAfter(); NodeLabels labelFieldBefore = parseLabelsField( before ); NodeLabels labelFieldAfter = parseLabelsField( after ); if ( !(labelFieldBefore.isInlined() && labelFieldAfter.isInlined() && before.getLabelField() == after.getLabelField()) ) { long[] labelsBefore = labelFieldBefore.getIfLoaded(); long[] labelsAfter = labelFieldAfter.getIfLoaded(); if ( labelsBefore != null && labelsAfter != null ) { if ( labelUpdates == null ) { labelUpdates = new ArrayList<>(); } labelUpdates.add( NodeLabelUpdate.labelChanges( command.getKey(), labelsBefore, labelsAfter, txId ) ); } } // for indexes return indexUpdatesExtractor.visitNodeCommand( command ); }
@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 ); }
@Override public boolean visitNodeCommand( NodeCommand command ) { nodeCommandsById.put( command.getKey(), command ); if ( !hasUpdates && mayResultInIndexUpdates( command ) ) { hasUpdates = true; } return false; }
@Override public boolean visitNodeCommand( Command.NodeCommand command ) { // acquire lock lockGroup.add( lockService.acquireNodeLock( command.getKey(), LockService.LockType.WRITE_LOCK ) ); // update store updateStore( neoStores.getNodeStore(), command ); return false; }
@Override public boolean visit( StorageCommand element ) { if ( element instanceof NodeCommand ) { nodeId = ((NodeCommand)element).getKey(); } return false; }