@Test public void shouldApplyUpdateUniquenessConstraintRuleSchemaRuleCommandToTheStore() throws Exception { // given final BatchTransactionApplier applier = newApplier( false ); final DynamicRecord record = DynamicRecord.dynamicRecord( 21, true ); final Collection<DynamicRecord> recordsAfter = singletonList( record ); final ConstraintRule rule = uniquenessConstraintRule( 0L, 1, 2, 3L ); final Command.SchemaRuleCommand command = new Command.SchemaRuleCommand( Collections.emptyList(), recordsAfter, rule ); // when boolean result = apply( applier, command::handle, transactionToApply ); // then assertFalse( result ); verify( schemaStore, times( 1 ) ).updateRecord( record ); verify( metaDataStore, times( 1 ) ).setLatestConstraintIntroducingTx( transactionId ); verify( cacheAccess, times( 1 ) ).addSchemaRule( rule ); }
@Test public void shouldApplyUpdateUniquenessConstraintRuleSchemaRuleCommandToTheStoreInRecovery() throws Exception { // given final BatchTransactionApplier applier = newApplier( true ); final DynamicRecord record = DynamicRecord.dynamicRecord( 21, true ); final Collection<DynamicRecord> recordsAfter = singletonList( record ); final ConstraintRule rule = uniquenessConstraintRule( 0L, 1, 2, 3L ); final Command.SchemaRuleCommand command = new Command.SchemaRuleCommand( Collections.emptyList(), recordsAfter, rule ); // when boolean result = apply( applier, command::handle, transactionToApply ); // then assertFalse( result ); verify( schemaStore, times( 1 ) ).setHighestPossibleIdInUse( record.getId() ); verify( schemaStore, times( 1 ) ).updateRecord( record ); verify( metaDataStore, times( 1 ) ).setLatestConstraintIntroducingTx( transactionId ); verify( cacheAccess, times( 1 ) ).addSchemaRule( rule ); }
@Test public void shouldApplyCreateUniquenessConstraintRuleSchemaRuleCommandToTheStore() throws Exception { // given final BatchTransactionApplier applier = newApplier( false ); final DynamicRecord record = DynamicRecord.dynamicRecord( 21, true ); record.setCreated(); final Collection<DynamicRecord> recordsAfter = singletonList( record ); final ConstraintRule rule = uniquenessConstraintRule( 0L, 1, 2, 3L ); final Command.SchemaRuleCommand command = new Command.SchemaRuleCommand( Collections.emptyList(), recordsAfter, rule ); // when boolean result = apply( applier, command::handle, transactionToApply ); // then assertFalse( result ); verify( schemaStore, times( 1 ) ).updateRecord( record ); verify( metaDataStore, times( 1 ) ).setLatestConstraintIntroducingTx( transactionId ); verify( cacheAccess, times( 1 ) ).addSchemaRule( rule ); }
@Test public void shouldApplyCreateUniquenessConstraintRuleSchemaRuleCommandToTheStoreInRecovery() throws Exception { // given final BatchTransactionApplier applier = newApplier( true ); final DynamicRecord record = DynamicRecord.dynamicRecord( 21, true ); record.setCreated(); final Collection<DynamicRecord> recordsAfter = singletonList( record ); final ConstraintRule rule = uniquenessConstraintRule( 0L, 1, 2, 3L ); final Command.SchemaRuleCommand command = new Command.SchemaRuleCommand( Collections.emptyList(), recordsAfter, rule ); // when boolean result = apply( applier, command::handle, transactionToApply ); // then assertFalse( result ); verify( schemaStore, times( 1 ) ).setHighestPossibleIdInUse( record.getId() ); verify( schemaStore, times( 1 ) ).updateRecord( record ); verify( metaDataStore, times( 1 ) ).setLatestConstraintIntroducingTx( transactionId ); verify( cacheAccess, times( 1 ) ).addSchemaRule( rule ); }
@Test public void shouldApplyDeleteUniquenessConstraintRuleSchemaRuleCommandToTheStore() throws Exception { // given final BatchTransactionApplier applier = newApplier( false ); final DynamicRecord record = DynamicRecord.dynamicRecord( 21, true ); record.setInUse( false ); final Collection<DynamicRecord> recordsAfter = singletonList( record ); final ConstraintRule rule = uniquenessConstraintRule( 0L, 1, 2, 3L ); final Command.SchemaRuleCommand command = new Command.SchemaRuleCommand( Collections.emptyList(), recordsAfter, rule ); // when boolean result = apply( applier, command::handle, transactionToApply ); // then assertFalse( result ); verify( schemaStore, times( 1 ) ).updateRecord( record ); verify( metaDataStore, never() ).setLatestConstraintIntroducingTx( transactionId ); verify( cacheAccess, times( 1 ) ).removeSchemaRuleFromCache( command.getKey() ); }
@Test public void shouldApplyDeleteUniquenessConstraintRuleSchemaRuleCommandToTheStoreInRecovery() throws Exception { // given final BatchTransactionApplier applier = newApplier( true ); final DynamicRecord record = DynamicRecord.dynamicRecord( 21, true ); record.setInUse( false ); final Collection<DynamicRecord> recordsAfter = singletonList( record ); final ConstraintRule rule = uniquenessConstraintRule( 0L, 1, 2, 3L ); final Command.SchemaRuleCommand command = new Command.SchemaRuleCommand( Collections.emptyList(), recordsAfter, rule ); // when boolean result = apply( applier, command::handle, transactionToApply ); // then assertFalse( result ); verify( schemaStore, times( 1 ) ).setHighestPossibleIdInUse( record.getId() ); verify( schemaStore, times( 1 ) ).updateRecord( record ); verify( metaDataStore, never() ).setLatestConstraintIntroducingTx( transactionId ); verify( cacheAccess, times( 1 ) ).removeSchemaRuleFromCache( command.getKey() ); }
@Test public void shouldSetLatestConstraintRule() throws Exception { // Given SchemaRecord beforeRecords = serialize( rule, id, true, true); SchemaRecord afterRecords = serialize( rule, id, true, false); when( neoStores.getSchemaStore() ).thenReturn( schemaStore ); when( neoStores.getMetaDataStore() ).thenReturn( metaDataStore ); ConstraintRule schemaRule = ConstraintRule.constraintRule( id, ConstraintDescriptorFactory.uniqueForLabel( labelId, propertyKey ), 0 ); // WHEN visitSchemaRuleCommand( storeApplier, new SchemaRuleCommand( beforeRecords, afterRecords, schemaRule ) ); // THEN verify( schemaStore ).updateRecord( Iterables.first( afterRecords ) ); verify( metaDataStore ).setLatestConstraintIntroducingTx( txId ); }
neoStores.getMetaDataStore().setLatestConstraintIntroducingTx( transactionId ); break; case DELETE:
@Override protected void initialiseNewStoreFile( PagedFile file ) throws IOException { super.initialiseNewStoreFile( file ); long storeVersionAsLong = MetaDataStore.versionStringToLong( storeVersion ); StoreId storeId = new StoreId( storeVersionAsLong ); pagedFile = file; setCreationTime( storeId.getCreationTime() ); setRandomNumber( storeId.getRandomId() ); // If metaDataStore.creationTime == metaDataStore.upgradeTime && metaDataStore.upgradeTransactionId == BASE_TX_ID // then store has never been upgraded setUpgradeTime( storeId.getCreationTime() ); setUpgradeTransaction( BASE_TX_ID, BASE_TX_CHECKSUM, BASE_TX_COMMIT_TIMESTAMP ); setCurrentLogVersion( 0 ); setLastCommittedAndClosedTransactionId( BASE_TX_ID, BASE_TX_CHECKSUM, BASE_TX_COMMIT_TIMESTAMP, BASE_TX_LOG_BYTE_OFFSET, BASE_TX_LOG_VERSION ); setStoreVersion( storeVersionAsLong ); setGraphNextProp( -1 ); setLatestConstraintIntroducingTx( 0 ); flush(); pagedFile = null; }
@Test public void testSetLatestConstraintTx() { // given Config config = Config.defaults(); StoreFactory sf = new StoreFactory( dir.databaseLayout(), config, new DefaultIdGeneratorFactory( fs.get() ), pageCacheRule.getPageCache( fs.get() ), fs.get(), LOG_PROVIDER, EmptyVersionContextSupplier.EMPTY ); // when NeoStores neoStores = sf.openAllNeoStores( true ); MetaDataStore metaDataStore = neoStores.getMetaDataStore(); // then the default is 0 assertEquals( 0L, metaDataStore.getLatestConstraintIntroducingTx() ); // when metaDataStore.setLatestConstraintIntroducingTx( 10L ); // then assertEquals( 10L, metaDataStore.getLatestConstraintIntroducingTx() ); // when neoStores.flush( IOLimiter.UNLIMITED ); neoStores.close(); neoStores = sf.openAllNeoStores(); // then the value should have been stored assertEquals( 10L, neoStores.getMetaDataStore().getLatestConstraintIntroducingTx() ); neoStores.close(); }
metaDataStore.setLatestConstraintIntroducingTx( 9 );
metaDataStore.setLatestConstraintIntroducingTx( 9 );
neoStores.getMetaDataStore().setLatestConstraintIntroducingTx( transactionId ); break; case DELETE:
@Override protected void initialiseNewStoreFile( PagedFile file ) throws IOException { super.initialiseNewStoreFile( file ); long storeVersionAsLong = MetaDataStore.versionStringToLong( storeVersion ); StoreId storeId = new StoreId( storeVersionAsLong ); pagedFile = file; setCreationTime( storeId.getCreationTime() ); setRandomNumber( storeId.getRandomId() ); // If metaDataStore.creationTime == metaDataStore.upgradeTime && metaDataStore.upgradeTransactionId == BASE_TX_ID // then store has never been upgraded setUpgradeTime( storeId.getCreationTime() ); setUpgradeTransaction( BASE_TX_ID, BASE_TX_CHECKSUM, BASE_TX_COMMIT_TIMESTAMP ); setCurrentLogVersion( 0 ); setLastCommittedAndClosedTransactionId( BASE_TX_ID, BASE_TX_CHECKSUM, BASE_TX_COMMIT_TIMESTAMP, BASE_TX_LOG_BYTE_OFFSET, BASE_TX_LOG_VERSION ); setStoreVersion( storeVersionAsLong ); setGraphNextProp( -1 ); setLatestConstraintIntroducingTx( 0 ); flush(); pagedFile = null; }