Refine search
private void prepareNeoStoreFile( String storeVersion ) throws IOException { File neoStoreFile = createNeoStoreFile(); long value = MetaDataStore.versionStringToLong( storeVersion ); try ( PageCache pageCache = pageCacheRule.getPageCache( fsRule.get() ) ) { MetaDataStore.setRecord( pageCache, neoStoreFile, STORE_VERSION, value ); } }
public StoreId getStoreId() { return new StoreId( getCreationTime(), getRandomNumber(), getStoreVersion(), getUpgradeTime(), upgradeTxIdField ); }
@Override public long getGraphPropertyReference() { return neoStores.getMetaDataStore().getGraphNextProp(); }
public Optional<String> getVersion( File neostoreFile ) throws IOException { long record = MetaDataStore.getRecord( pageCache, neostoreFile, STORE_VERSION ); if ( record == MetaDataRecordFormat.FIELD_NOT_PRESENT ) { return Optional.empty(); } return Optional.of( MetaDataStore.versionLongToString( record ) ); }
@Override public void setLastCommittedAndClosedTransactionId( long transactionId, long checksum, long commitTimestamp, long byteOffset, long logVersion ) { assertNotClosed(); setRecord( Position.LAST_TRANSACTION_ID, transactionId ); setRecord( Position.LAST_TRANSACTION_CHECKSUM, checksum ); setRecord( Position.LAST_CLOSED_TRANSACTION_LOG_VERSION, logVersion ); setRecord( Position.LAST_CLOSED_TRANSACTION_LOG_BYTE_OFFSET, byteOffset ); setRecord( Position.LAST_TRANSACTION_COMMIT_TIMESTAMP, commitTimestamp ); checkInitialized( lastCommittingTxField.get() ); lastCommittingTxField.set( transactionId ); lastClosedTx.set( transactionId, new long[]{logVersion, byteOffset} ); highestCommittedTransaction.set( transactionId, checksum, commitTimestamp ); } /**
FileSystemAbstraction fs = spy( fileSystem ); StoreChannel tempChannel; when( tempChannel = fs.open( file, OpenMode.READ_WRITE ) ).then( ignored -> StoreChannel channelSpy = spy( channel ); channelUsedToCreateFile[0] = channelSpy; channel = channelSpy; IndexProviderStore store = new IndexProviderStore( file, fs, MetaDataStore.versionStringToLong( "3.5" ), false );
ExplicitIndexTransactionState explicitIndexState = mock( ExplicitIndexTransactionState.class ); auxTxStateManager.registerProvider( new ExplicitIndexTransactionStateProvider( null, null ) when( explicitIndexState.hasChanges() ).thenReturn( true ); doAnswer( invocation -> when( metaDataStore.getLastCommittedTransactionId() ).thenReturn( 7L ); transaction.success();
@Test( expected = IllegalArgumentException.class ) public void shouldThrowWhenTryingToCreateFileThatAlreadyExists() { // Given FileSystemAbstraction fs = mock( FileSystemAbstraction.class ); when( fs.fileExists( file ) ).thenReturn( false ).thenReturn( true ); when( fs.getFileSize( file ) ).thenReturn( 42L ); // When new IndexProviderStore( file, fs, MetaDataStore.versionStringToLong( "3.5" ), false ); // Then // exception is thrown }
@Test public void transactionsStartedBeforeAConstraintWasCreatedAreDisallowed() { // Given NeoStores store = mock( NeoStores.class ); MetaDataStore metaDataStore = mock( MetaDataStore.class ); when( store.getMetaDataStore() ).thenReturn( metaDataStore ); IndexingService indexes = mock( IndexingService.class ); when( metaDataStore.getLatestConstraintIntroducingTx() ).thenReturn( 10L ); IntegrityValidator validator = new IntegrityValidator( store, indexes ); // When try { validator.validateTransactionStartKnowledge( 1 ); fail( "Should have thrown integrity error." ); } catch ( Exception e ) { // good } } }
@Test public void shouldGenerateTransactionInformationWhenLogsNotPresent() throws Exception { // given long txId = 42; DatabaseLayout databaseLayout = directory.databaseLayout(); File neoStore = databaseLayout.metadataStore(); neoStore.createNewFile(); Config config = mock( Config.class ); LogService logService = new SimpleLogService( NullLogProvider.getInstance(), NullLogProvider.getInstance() ); // when // ... transaction info not in neo store assertEquals( FIELD_NOT_PRESENT, getRecord( pageCache, neoStore, LAST_TRANSACTION_ID ) ); assertEquals( FIELD_NOT_PRESENT, getRecord( pageCache, neoStore, LAST_TRANSACTION_CHECKSUM ) ); assertEquals( FIELD_NOT_PRESENT, getRecord( pageCache, neoStore, LAST_TRANSACTION_COMMIT_TIMESTAMP ) ); // ... and with migrator StoreMigrator migrator = new StoreMigrator( fileSystemRule.get(), pageCache, config, logService, jobScheduler ); TransactionId actual = migrator.extractTransactionIdInformation( neoStore, txId ); // then assertEquals( txId, actual.transactionId() ); assertEquals( TransactionIdStore.UNKNOWN_TX_CHECKSUM, actual.checksum() ); assertEquals( TransactionIdStore.UNKNOWN_TX_COMMIT_TIMESTAMP, actual.commitTimestamp() ); }
@Test public void shouldExtractTransactionInformationFromMetaDataStore() throws Exception { // given // ... variables long txId = 42; long checksum = 123456789123456789L; long timestamp = 919191919191919191L; TransactionId expected = new TransactionId( txId, checksum, timestamp ); // ... and files DatabaseLayout databaseLayout = directory.databaseLayout(); File neoStore = databaseLayout.metadataStore(); neoStore.createNewFile(); // ... and mocks Config config = mock( Config.class ); LogService logService = mock( LogService.class ); // when // ... data in record setRecord( pageCache, neoStore, LAST_TRANSACTION_ID, txId ); setRecord( pageCache, neoStore, LAST_TRANSACTION_CHECKSUM, checksum ); setRecord( pageCache, neoStore, LAST_TRANSACTION_COMMIT_TIMESTAMP, timestamp ); // ... and with migrator StoreMigrator migrator = new StoreMigrator( fileSystemRule.get(), pageCache, config, logService, jobScheduler ); TransactionId actual = migrator.extractTransactionIdInformation( neoStore, txId ); // then assertEquals( expected, actual ); }
@Test public void upgradedNeoStoreShouldHaveNewUpgradeTimeAndUpgradeId() throws Exception { // Given fileSystem.deleteFile( databaseLayout.file( INTERNAL_LOG_FILE ) ); PageCache pageCache = pageCacheRule.getPageCache( fileSystem ); UpgradableDatabase upgradableDatabase = getUpgradableDatabase( pageCache ); // When newUpgrader( upgradableDatabase, allowMigrateConfig, pageCache ).migrateIfNeeded( databaseLayout ); // Then StoreFactory factory = new StoreFactory( databaseLayout, allowMigrateConfig, new DefaultIdGeneratorFactory( fileSystem ), pageCache, fileSystem, NullLogProvider.getInstance(), EmptyVersionContextSupplier.EMPTY ); try ( NeoStores neoStores = factory.openAllNeoStores() ) { assertThat( neoStores.getMetaDataStore().getUpgradeTransaction(), equalTo( neoStores.getMetaDataStore().getLastCommittedTransaction() ) ); assertThat( neoStores.getMetaDataStore().getUpgradeTime(), not( equalTo( MetaDataStore.FIELD_NOT_INITIALIZED ) ) ); long minuteAgo = System.currentTimeMillis() - MINUTES.toMillis( 1 ); assertThat( neoStores.getMetaDataStore().getUpgradeTime(), greaterThan( minuteAgo ) ); } }
long storeVersion = versionStringToLong( Standard.LATEST_RECORD_FORMATS.storeVersion()); writeCorrectMetaDataRecord( file, positions, storeVersion ); try ( MetaDataStore store = newMetaDataStore() ) MetaDataRecord record = store.newRecord(); try ( PageCursor cursor = store.openPageCursorForReading( 0 ) ) long highId = store.getHighId(); for ( long id = 0; id < highId; id++ ) store.getRecordByCursor( id, record, RecordLoad.NORMAL, cursor ); if ( record.inUse() ) assertThat( actualValues, is( expectedValues ) );
@Test public void mustSupportScanningAllRecords() throws Exception { File file = createMetaDataFile(); MetaDataStore.Position[] positions = MetaDataStore.Position.values(); long storeVersion = versionStringToLong( Standard.LATEST_RECORD_FORMATS.storeVersion()); writeCorrectMetaDataRecord( file, positions, storeVersion ); List<Long> actualValues = new ArrayList<>(); try ( MetaDataStore store = newMetaDataStore() ) { store.scanAllRecords( record -> { actualValues.add( record.getValue() ); return false; } ); } List<Long> expectedValues = Arrays.stream( positions ).map( p -> { if ( p == MetaDataStore.Position.STORE_VERSION ) { return storeVersion; } else { return p.ordinal() + 1L; } } ).collect( Collectors.toList() ); assertThat( actualValues, is( expectedValues ) ); }
@Test public void lastTxCommitTimestampShouldBeBaseInNewStore() { try ( MetaDataStore metaDataStore = newMetaDataStore() ) { long timestamp = metaDataStore.getLastCommittedTransaction().commitTimestamp(); assertThat( timestamp, equalTo( TransactionIdStore.BASE_TX_COMMIT_TIMESTAMP ) ); } }
@Test public void getUpgradeTimeShouldFailWhenStoreIsClosed() { MetaDataStore metaDataStore = newMetaDataStore(); metaDataStore.close(); try { metaDataStore.getUpgradeTime(); fail( "Expected exception reading from MetaDataStore after being closed." ); } catch ( Exception e ) { assertThat( e, instanceOf( IllegalStateException.class ) ); } }
@Test public void getLatestConstraintIntroducingTxShouldFailWhenStoreIsClosed() { MetaDataStore metaDataStore = newMetaDataStore(); metaDataStore.close(); try { metaDataStore.getLatestConstraintIntroducingTx(); fail( "Expected exception reading from MetaDataStore after being closed." ); } catch ( Exception e ) { assertThat( e, instanceOf( IllegalStateException.class ) ); } }
@Test public void getLastCommittedTransactionShouldFailWhenStoreIsClosed() { MetaDataStore metaDataStore = newMetaDataStore(); metaDataStore.close(); try { metaDataStore.getLastCommittedTransaction(); fail( "Expected exception reading from MetaDataStore after being closed." ); } catch ( Exception e ) { assertThat( e, instanceOf( IllegalStateException.class ) ); } }
@Test public void getCreationTimeShouldFailWhenStoreIsClosed() { MetaDataStore metaDataStore = newMetaDataStore(); metaDataStore.close(); try { metaDataStore.getCreationTime(); fail( "Expected exception reading from MetaDataStore after being closed." ); } catch ( Exception e ) { assertThat( e, instanceOf( IllegalStateException.class ) ); } }
@Test public void getRandomNumberShouldFailWhenStoreIsClosed() { MetaDataStore metaDataStore = newMetaDataStore(); metaDataStore.close(); try { metaDataStore.getRandomNumber(); fail( "Expected exception reading from MetaDataStore after being closed." ); } catch ( Exception e ) { assertThat( e, instanceOf( IllegalStateException.class ) ); } }