public FileSystemAbstraction fileSystem() { return fs.get(); }
@Test public void shouldBeAbleToRetrieveTheHighestLogVersion() throws Throwable { // given LogFiles files = createLogFiles(); DatabaseLayout databaseLayout = testDirectory.databaseLayout(); fileSystemRule.create( databaseLayout.file( getVersionedLogFileName( "1" ) ) ).close(); fileSystemRule.create( databaseLayout.file( getVersionedLogFileName( "some", "4" ) ) ).close(); fileSystemRule.create( databaseLayout.file( getVersionedLogFileName( "3" ) ) ).close(); fileSystemRule.create( databaseLayout.file( filename ) ).close(); // when final long highestLogVersion = files.getHighestLogVersion(); // then assertEquals( 3, highestLogVersion ); files.shutdown(); }
@Test public void shouldVisitEachLofFile() throws Throwable { // given LogFiles files = createLogFiles(); DatabaseLayout databaseLayout = testDirectory.databaseLayout(); fileSystemRule.create( databaseLayout.file( getVersionedLogFileName( "1" ) ) ).close(); fileSystemRule.create( databaseLayout.file( getVersionedLogFileName( "some", "2" ) ) ).close(); fileSystemRule.create( databaseLayout.file( getVersionedLogFileName( "3" ) ) ).close(); fileSystemRule.create( databaseLayout.file( filename ) ).close(); // when final List<File> seenFiles = new ArrayList<>(); final List<Long> seenVersions = new ArrayList<>(); files.accept( ( file, logVersion ) -> { seenFiles.add( file ); seenVersions.add( logVersion ); } ); // then assertThat( seenFiles, containsInAnyOrder( databaseLayout.file( getVersionedLogFileName( filename, "1" ) ), databaseLayout.file( getVersionedLogFileName( filename, "3" ) ) ) ); assertThat( seenVersions, containsInAnyOrder( 1L, 3L ) ); files.shutdown(); }
@Before public void setUp() { fs = fileSystemRule.get(); file = testDirectory.file( "ids" ); }
@Test public void shouldReturnANegativeValueIfThereAreNoLogFiles() throws Throwable { // given LogFiles files = createLogFiles(); DatabaseLayout databaseLayout = testDirectory.databaseLayout(); fileSystemRule.create( databaseLayout.file( getVersionedLogFileName( "some", "4" ) ) ).close(); fileSystemRule.create( databaseLayout.file( filename ) ).close(); // when final long highestLogVersion = files.getHighestLogVersion(); // then assertEquals( -1, highestLogVersion ); files.shutdown(); }
@Test public void allowToLockSameDirectoryIfItWasUnlocked() throws IOException { StoreLayout storeLayout = testDirectory.storeLayout(); try ( GlobalStoreLocker storeLocker = new GlobalStoreLocker( fileSystemRule.get(), storeLayout ) ) { storeLocker.checkLock(); } try ( GlobalStoreLocker storeLocker = new GlobalStoreLocker( fileSystemRule.get(), storeLayout ) ) { storeLocker.checkLock(); } }
@Test public void failToLockSameFolderAcrossIndependentLockers() throws Exception { StoreLayout storeLayout = testDirectory.storeLayout(); try ( GlobalStoreLocker storeLocker = new GlobalStoreLocker( fileSystemRule.get(), storeLayout ) ) { storeLocker.checkLock(); try ( GlobalStoreLocker locker = new GlobalStoreLocker( fileSystemRule.get(), storeLayout ) ) { locker.checkLock(); fail("directory should be locked"); } catch ( StoreLockException expected ) { // expected } try ( GlobalStoreLocker locker = new GlobalStoreLocker( fileSystemRule.get(), storeLayout ) ) { locker.checkLock(); fail("directory should be locked"); } catch ( StoreLockException expected ) { // expected } } }
PageCache pageCache = pageCacheRule.getPageCache( fileSystemRule.get() ); List<NodeLabelUpdate> existingData = new ArrayList<>(); existingData.add( NodeLabelUpdate.labelChanges( 1, new long[0], new long[]{2, 1} ) ); try nativeLabelScanStore = new NativeLabelScanStore( pageCache, testDirectory.databaseLayout(), fileSystemRule.get(), changeStream, false, new Monitors(), immediate() ); nativeLabelScanStore.init();
@Before public void setupPagedFile() throws IOException { PageCache pageCache = pageCacheRule .getPageCache( fileSystemRule.get(), config().withPageSize( PAGE_SIZE ).withAccessChecks( true ) ); pagedFile = pageCache .map( testDirectory.file( FILE_NAME ), PAGE_SIZE, CREATE, DELETE_ON_CLOSE ); }
private void verifyTransactionLogs( File txDirectory, File storeDir ) throws IOException { FileSystemAbstraction fileSystem = fileSystemRule.get(); LogFiles storeDirLogs = LogFilesBuilder.logFilesBasedOnlyBuilder( storeDir, fileSystem ).build(); assertFalse( storeDirLogs.versionExists( 0 ) ); LogFiles txDirectoryLogs = LogFilesBuilder.logFilesBasedOnlyBuilder( txDirectory, fileSystem ).build(); assertTrue( txDirectoryLogs.versionExists( 0 ) ); try ( PhysicalLogVersionedStoreChannel physicalLogVersionedStoreChannel = txDirectoryLogs.openForVersion( 0 ) ) { assertThat( physicalLogVersionedStoreChannel.size(), greaterThan( 0L ) ); } }
@Test public void labelScanStoreIsDirtyWhenIndexIsNotClean() throws IOException { PageCache pageCache = pageCacheRule.getPageCache( fileSystemRule.get() ); createDirtyIndex( pageCache ); Monitors monitors = new Monitors(); RecordingMonitor monitor = new RecordingMonitor(); monitors.addMonitorListener( monitor ); NativeLabelScanStore nativeLabelScanStore = new NativeLabelScanStore( pageCache, testDirectory.databaseLayout(), fileSystemRule.get(), EMPTY, true, monitors, ignore() ); nativeLabelScanStore.init(); nativeLabelScanStore.start(); assertTrue( nativeLabelScanStore.isDirty() ); nativeLabelScanStore.shutdown(); }
@Test public void doNotRebuildIfOpenedInReadOnlyModeAndIndexIsNotClean() throws IOException { PageCache pageCache = pageCacheRule.getPageCache( fileSystemRule.get() ); createDirtyIndex( pageCache ); Monitors monitors = new Monitors(); RecordingMonitor monitor = new RecordingMonitor(); monitors.addMonitorListener( monitor ); NativeLabelScanStore nativeLabelScanStore = new NativeLabelScanStore( pageCache, testDirectory.databaseLayout(), fileSystemRule.get(), EMPTY, true, monitors, ignore() ); nativeLabelScanStore.init(); nativeLabelScanStore.start(); assertTrue( monitor.notValid ); assertFalse( monitor.rebuilt ); assertFalse( monitor.rebuilding ); nativeLabelScanStore.shutdown(); }
@Test public void allowMultipleCallstoActuallyStoreLocker() throws IOException { StoreLayout storeLayout = testDirectory.storeLayout(); try ( GlobalStoreLocker storeLocker = new GlobalStoreLocker( fileSystemRule.get(), storeLayout ) ) { storeLocker.checkLock(); storeLocker.checkLock(); storeLocker.checkLock(); storeLocker.checkLock(); storeLocker.checkLock(); } } }
@Test public void mustBeDirtyIfFailedDuringRebuild() throws Exception { // given PageCache pageCache = pageCacheRule.getPageCache( fileSystemRule.get() ); createDirtyIndex( pageCache ); // when RecordingMonitor monitor = new RecordingMonitor(); Monitors monitors = new Monitors(); monitors.addMonitorListener( monitor ); NativeLabelScanStore nativeLabelScanStore = new NativeLabelScanStore( pageCache, testDirectory.databaseLayout(), fileSystemRule.get(), EMPTY, false, monitors, immediate() ); nativeLabelScanStore.init(); nativeLabelScanStore.start(); // then assertTrue( monitor.notValid ); assertTrue( monitor.rebuilding ); assertTrue( monitor.rebuilt ); nativeLabelScanStore.shutdown(); }
private void createDirtyIndex( PageCache pageCache ) throws IOException { NativeLabelScanStore nativeLabelScanStore = null; try { nativeLabelScanStore = new NativeLabelScanStore( pageCache, testDirectory.databaseLayout(), fileSystemRule.get(), THROWING_STREAM, false, new Monitors(), immediate() ); nativeLabelScanStore.init(); nativeLabelScanStore.start(); } catch ( IllegalArgumentException e ) { if ( nativeLabelScanStore != null ) { nativeLabelScanStore.shutdown(); } } }