public void setUpgradeTime( long time ) { synchronized ( upgradeTimeLock ) { setRecord( Position.UPGRADE_TIME, time ); upgradeTimeField = time; } }
public void setCreationTime( long time ) { synchronized ( creationTimeLock ) { setRecord( Position.TIME, time ); creationTimeField = time; } }
public void setRandomNumber( long nr ) { synchronized ( randomNumberLock ) { setRecord( Position.RANDOM_NUMBER, nr ); randomNumberField = nr; } }
@Override public void setCurrentLogVersion( long version ) { synchronized ( logVersionLock ) { setRecord( Position.LOG_VERSION, version ); versionField = version; } }
public void setLatestConstraintIntroducingTx( long latestConstraintIntroducingTx ) { synchronized ( lastConstraintIntroducingTxLock ) { setRecord( Position.LAST_CONSTRAINT_TRANSACTION, latestConstraintIntroducingTx ); latestConstraintIntroducingTxField = latestConstraintIntroducingTx; } }
public void setStoreVersion( long version ) { synchronized ( storeVersionLock ) { setRecord( Position.STORE_VERSION, version ); storeVersionField = version; } }
public void setGraphNextProp( long propId ) { synchronized ( graphNextPropLock ) { setRecord( Position.FIRST_GRAPH_PROPERTY, propId ); graphNextPropField = propId; } }
@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 ); } /**
private void writeCorrectMetaDataRecord( File file, MetaDataStore.Position[] positions, long storeVersion ) throws IOException { for ( MetaDataStore.Position position : positions ) { if ( position == MetaDataStore.Position.STORE_VERSION ) { MetaDataStore.setRecord( pageCache, file, position, storeVersion ); } else { MetaDataStore.setRecord( pageCache, file, position, position.ordinal() + 1 ); } } }
public void setUpgradeTransaction( long id, long checksum, long timestamp ) { long pageId = pageIdForRecord( Position.UPGRADE_TRANSACTION_ID.id ); assert pageId == pageIdForRecord( Position.UPGRADE_TRANSACTION_CHECKSUM.id ); synchronized ( upgradeTransactionLock ) { try ( PageCursor cursor = pagedFile.io( pageId, PF_SHARED_WRITE_LOCK ) ) { if ( !cursor.next() ) { throw new UnderlyingStorageException( "Could not access MetaDataStore page " + pageId ); } setRecord( cursor, Position.UPGRADE_TRANSACTION_ID, id ); setRecord( cursor, Position.UPGRADE_TRANSACTION_CHECKSUM, checksum ); setRecord( cursor, Position.UPGRADE_TRANSACTION_COMMIT_TIMESTAMP, timestamp ); upgradeTxIdField = id; upgradeTxChecksumField = checksum; upgradeCommitTimestampField = timestamp; upgradeTransaction = new TransactionId( id, checksum, timestamp ); } catch ( IOException e ) { throw new UnderlyingStorageException( e ); } } }
public void setLastTransactionCommitTimestamp( long timestamp ) { // Preventing race with transactionCommitted() and assure record is consistent with highestCommittedTransaction synchronized ( transactionCommittedLock ) { setRecord( Position.LAST_TRANSACTION_COMMIT_TIMESTAMP, timestamp ); TransactionId transactionId = highestCommittedTransaction.get(); highestCommittedTransaction.set( transactionId.transactionId(), transactionId.checksum(), timestamp ); } }
@Test( expected = UnderlyingStorageException.class ) public void staticSetRecordMustThrowOnPageOverflow() throws Exception { fakePageCursorOverflow = true; MetaDataStore.setRecord( pageCacheWithFakeOverflow, createMetaDataFile(), MetaDataStore.Position.FIRST_GRAPH_PROPERTY, 4242 ); }
@Override public void transactionClosed( long transactionId, long logVersion, long byteOffset ) { if ( lastClosedTx.offer( transactionId, new long[]{logVersion, byteOffset} ) ) { long pageId = pageIdForRecord( Position.LAST_CLOSED_TRANSACTION_LOG_VERSION.id ); assert pageId == pageIdForRecord( Position.LAST_CLOSED_TRANSACTION_LOG_BYTE_OFFSET.id ); synchronized ( transactionClosedLock ) { try ( PageCursor cursor = pagedFile.io( pageId, PF_SHARED_WRITE_LOCK ) ) { if ( cursor.next() ) { long[] lastClosedTransactionData = lastClosedTx.get(); setRecord( cursor, Position.LAST_CLOSED_TRANSACTION_LOG_VERSION, lastClosedTransactionData[1] ); setRecord( cursor, Position.LAST_CLOSED_TRANSACTION_LOG_BYTE_OFFSET, lastClosedTransactionData[2] ); } } catch ( IOException e ) { throw new UnderlyingStorageException( e ); } } } }
@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 ); }
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 ); } }
private void prepareEmpty23Database() throws IOException { new TestGraphDatabaseFactory().newEmbeddedDatabase( storeDir ).shutdown(); fileSystem.deleteFile( nativeLabelIndex ); MetaDataStore.setRecord( pageCache, databaseLayout.metadataStore(), Position.STORE_VERSION, versionStringToLong( StandardV2_3.STORE_VERSION ) ); }
@Test public void setVersion() throws Exception { FileSystemAbstraction fileSystem = fs.get(); File storeDir = dir.directory(); createTestDatabase( fileSystem, storeDir ).shutdown(); DatabaseLayout databaseLayout = dir.databaseLayout(); assertEquals( 0, MetaDataStore.setRecord( pageCache, databaseLayout.metadataStore(), Position.LOG_VERSION, 10 ) ); assertEquals( 10, MetaDataStore.setRecord( pageCache, databaseLayout.metadataStore(), Position.LOG_VERSION, 12 ) ); Config config = Config.defaults(); StoreFactory sf = getStoreFactory( config, databaseLayout, fileSystem, LOG_PROVIDER ); NeoStores neoStores = sf.openAllNeoStores(); assertEquals( 12, neoStores.getMetaDataStore().getCurrentLogVersion() ); neoStores.close(); }
@Test public void shouldReportFileWithIncorrectVersion() throws IOException { // given File neoStore = emptyFile( fileSystemRule.get() ); long v1 = MetaDataStore.versionStringToLong( "V1" ); PageCache pageCache = pageCacheRule.getPageCache( fileSystemRule.get() ); MetaDataStore.setRecord( pageCache, neoStore, MetaDataStore.Position.STORE_VERSION, v1 ); StoreVersionCheck storeVersionCheck = new StoreVersionCheck( pageCache ); // when StoreVersionCheck.Result result = storeVersionCheck.hasVersion( neoStore, "V2" ); // then assertFalse( result.outcome.isSuccessful() ); assertEquals( StoreVersionCheck.Result.Outcome.unexpectedStoreVersion, result.outcome ); assertEquals( "V1", result.actualVersion ); }
@Test public void shouldReportFileWithCorrectVersion() throws IOException { // given File neoStore = emptyFile( fileSystemRule.get() ); long v1 = MetaDataStore.versionStringToLong( "V1" ); PageCache pageCache = pageCacheRule.getPageCache( fileSystemRule.get() ); MetaDataStore.setRecord( pageCache, neoStore, MetaDataStore.Position.STORE_VERSION, v1 ); StoreVersionCheck storeVersionCheck = new StoreVersionCheck( pageCache ); // when StoreVersionCheck.Result result = storeVersionCheck.hasVersion( neoStore, "V1" ); // then assertTrue( result.outcome.isSuccessful() ); assertEquals( StoreVersionCheck.Result.Outcome.ok, result.outcome ); assertNull( result.actualVersion ); }
private void extractTransactionalInformationFromLogs( String path, File customLogLocation, DatabaseLayout databaseLayout, File storeDir ) throws IOException { LogService logService = new SimpleLogService( NullLogProvider.getInstance(), NullLogProvider.getInstance() ); File neoStore = databaseLayout.metadataStore(); GraphDatabaseService database = new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder( storeDir ) .setConfig( logical_logs_location, path ).newGraphDatabase(); for ( int i = 0; i < 10; i++ ) { try ( Transaction transaction = database.beginTx() ) { Node node = database.createNode(); transaction.success(); } } database.shutdown(); MetaDataStore.setRecord( pageCache, neoStore, MetaDataStore.Position.LAST_CLOSED_TRANSACTION_LOG_VERSION, MetaDataRecordFormat.FIELD_NOT_PRESENT ); Config config = Config.defaults( logical_logs_location, path ); StoreMigrator migrator = new StoreMigrator( fileSystemRule.get(), pageCache, config, logService, jobScheduler ); LogPosition logPosition = migrator.extractTransactionLogPosition( neoStore, databaseLayout, 100 ); File[] logFiles = customLogLocation.listFiles(); assertNotNull( logFiles ); assertEquals( 0, logPosition.getLogVersion() ); assertEquals( logFiles[0].length(), logPosition.getByteOffset() ); }