private static long readLogVersion( PageCache pageCache, File neoStore ) throws IOException { try { return MetaDataStore.getRecord( pageCache, neoStore, MetaDataStore.Position.LOG_VERSION ); } catch ( NoSuchFileException ignore ) { return 0; } } }
public static StoreId getStoreId( PageCache pageCache, File neoStore ) throws IOException { return new StoreId( getRecord( pageCache, neoStore, Position.TIME ), getRecord( pageCache, neoStore, Position.RANDOM_NUMBER ), getRecord( pageCache, neoStore, Position.STORE_VERSION ), getRecord( pageCache, neoStore, Position.UPGRADE_TIME ), getRecord( pageCache, neoStore, Position.UPGRADE_TRANSACTION_ID ) ); }
public ReadOnlyTransactionIdStore( PageCache pageCache, DatabaseLayout databaseLayout ) throws IOException { long id = 0; long checksum = 0; long logVersion = 0; long byteOffset = 0; if ( NeoStores.isStorePresent( pageCache, databaseLayout ) ) { File neoStore = databaseLayout.metadataStore(); id = getRecord( pageCache, neoStore, Position.LAST_TRANSACTION_ID ); checksum = getRecord( pageCache, neoStore, Position.LAST_TRANSACTION_CHECKSUM ); logVersion = getRecord( pageCache, neoStore, Position.LAST_CLOSED_TRANSACTION_LOG_VERSION ); byteOffset = getRecord( pageCache, neoStore, Position.LAST_CLOSED_TRANSACTION_LOG_BYTE_OFFSET ); } this.transactionId = id; this.transactionChecksum = checksum; this.logVersion = logVersion; this.byteOffset = byteOffset; }
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 ) ); }
TransactionId extractTransactionIdInformation( File neoStore, long lastTransactionId ) throws IOException { long checksum = MetaDataStore.getRecord( pageCache, neoStore, Position.LAST_TRANSACTION_CHECKSUM ); long commitTimestamp = MetaDataStore.getRecord( pageCache, neoStore, Position.LAST_TRANSACTION_COMMIT_TIMESTAMP ); if ( checksum != FIELD_NOT_PRESENT && commitTimestamp != FIELD_NOT_PRESENT ) { return new TransactionId( lastTransactionId, checksum, commitTimestamp ); } return specificTransactionInformationSupplier( lastTransactionId ); }
long value = MetaDataStore.getRecord( pageCache, neoStoreFile, STORE_VERSION ); if ( value != MetaDataRecordFormat.FIELD_NOT_PRESENT )
@Test( expected = UnderlyingStorageException.class ) public void staticGetRecordMustThrowOnPageOverflow() throws Exception { File metaDataFile = createMetaDataFile(); MetaDataStore.setRecord( pageCacheWithFakeOverflow, metaDataFile, MetaDataStore.Position.FIRST_GRAPH_PROPERTY, 4242 ); fakePageCursorOverflow = true; MetaDataStore.getRecord( pageCacheWithFakeOverflow, metaDataFile, MetaDataStore.Position.FIRST_GRAPH_PROPERTY ); }
LogPosition extractTransactionLogPosition( File neoStore, DatabaseLayout sourceDirectoryStructure, long lastTxId ) throws IOException { long lastClosedTxLogVersion = MetaDataStore.getRecord( pageCache, neoStore, Position.LAST_CLOSED_TRANSACTION_LOG_VERSION ); long lastClosedTxLogByteOffset = MetaDataStore.getRecord( pageCache, neoStore, Position.LAST_CLOSED_TRANSACTION_LOG_BYTE_OFFSET ); if ( lastClosedTxLogVersion != MetaDataRecordFormat.FIELD_NOT_PRESENT && lastClosedTxLogByteOffset != MetaDataRecordFormat.FIELD_NOT_PRESENT ) { return new LogPosition( lastClosedTxLogVersion, lastClosedTxLogByteOffset ); } // The legacy store we're migrating doesn't have this record in neostore so try to extract it from tx log if ( lastTxId == TransactionIdStore.BASE_TX_ID ) { return new LogPosition( BASE_TX_LOG_VERSION, BASE_TX_LOG_BYTE_OFFSET ); } LogFiles logFiles = LogFilesBuilder.activeFilesBuilder( sourceDirectoryStructure, fileSystem, pageCache ) .withConfig( config ) .build(); long logVersion = logFiles.getHighestLogVersion(); if ( logVersion == -1 ) { return new LogPosition( BASE_TX_LOG_VERSION, BASE_TX_LOG_BYTE_OFFSET ); } long offset = fileSystem.getFileSize( logFiles.getHighestLogFile() ); return new LogPosition( logVersion, offset ); }
private void verifyRecordFormat() { try { String expectedStoreVersion = recordFormats.storeVersion(); long record = getRecord( pageCache, metadataStore, STORE_VERSION ); if ( record != MetaDataRecordFormat.FIELD_NOT_PRESENT ) { String actualStoreVersion = versionLongToString( record ); RecordFormats actualStoreFormat = RecordFormatSelector.selectForVersion( actualStoreVersion ); if ( !isCompatibleFormats( actualStoreFormat ) ) { throw new UnexpectedStoreVersionException( actualStoreVersion, expectedStoreVersion ); } } } catch ( NoSuchFileException e ) { // Occurs when there is no file, which is obviously when creating a store. // Caught as an exception because we want to leave as much interaction with files as possible // to the page cache. } catch ( IOException e ) { throw new UnderlyingStorageException( e ); } }
@Override public void migrate( DatabaseLayout directoryLayout, DatabaseLayout migrationLayout, ProgressReporter progressMonitor, String versionToMigrateFrom, String versionToMigrateTo ) throws IOException { if ( countStoreRebuildRequired( versionToMigrateFrom ) ) { // create counters from scratch fileOperation( DELETE, fileSystem, migrationLayout, migrationLayout, COUNTS_STORE_FILES, true, null ); File neoStore = directoryLayout.metadataStore(); long lastTxId = MetaDataStore.getRecord( pageCache, neoStore, Position.LAST_TRANSACTION_ID ); try { rebuildCountsFromScratch( directoryLayout, migrationLayout, lastTxId, progressMonitor, versionToMigrateTo, pageCache, NullLogProvider.getInstance() ); } catch ( StoreFailureException e ) { //This means that we did not perform a full migration, as the formats had the same capabilities. Thus // we should use the store directory for information when rebuilding the count store. Note that we // still put the new count store in the migration directory. rebuildCountsFromScratch( directoryLayout, migrationLayout, lastTxId, progressMonitor, versionToMigrateFrom, pageCache, NullLogProvider.getInstance() ); } migrated = true; } }
@Test public void shouldGenerateTransactionInformationWhenLogsAreEmpty() throws Exception { // given long txId = 1; 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.BASE_TX_CHECKSUM, actual.checksum() ); assertEquals( TransactionIdStore.BASE_TX_COMMIT_TIMESTAMP, actual.commitTimestamp() ); }
@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() ); }
long lastTxId = MetaDataStore.getRecord( pageCache, neoStore, Position.LAST_TRANSACTION_ID ); TransactionId lastTxInfo = extractTransactionIdInformation( neoStore, lastTxId ); LogPosition lastTxLogPosition = extractTransactionLogPosition( neoStore, directoryLayout, lastTxId );
MetaDataStore.getRecord( pageCache, storeDirNeoStore, Position.LAST_TRANSACTION_ID ) ); MetaDataStore.setRecord( pageCache, migrationDirNeoStore, Position.UPGRADE_TIME, System.currentTimeMillis() );
assertEquals( logVersion, MetaDataStore.getRecord( pageCache, neoStore, MetaDataStore.Position.LOG_VERSION ) );
assertEquals( logVersion, MetaDataStore.getRecord( pageCache, neoStore, MetaDataStore.Position.LOG_VERSION ) );
private static long readLogVersion( PageCache pageCache, File neoStore ) throws IOException { try { return MetaDataStore.getRecord( pageCache, neoStore, MetaDataStore.Position.LOG_VERSION ); } catch ( NoSuchFileException ignore ) { return 0; } } }
public static StoreId getStoreId( PageCache pageCache, File neoStore ) throws IOException { return new StoreId( getRecord( pageCache, neoStore, Position.TIME ), getRecord( pageCache, neoStore, Position.RANDOM_NUMBER ), getRecord( pageCache, neoStore, Position.STORE_VERSION ), getRecord( pageCache, neoStore, Position.UPGRADE_TIME ), getRecord( pageCache, neoStore, Position.UPGRADE_TRANSACTION_ID ) ); }
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 ) ); }