@Override public File rootDirectory() { return parentStructure.rootDirectory(); }
private File archiveFile() { File indexDir = nativeIndexDirectoryStructure( db.databaseLayout() ).rootDirectory(); File[] files = indexDir.listFiles( pathname -> pathname.isFile() && pathname.getName().startsWith( "archive-" ) ); if ( files == null || files.length == 0 ) { return null; } assertEquals( 1, files.length ); return files[0]; }
@Override public void migrate( DatabaseLayout directoryLayout, DatabaseLayout migrationLayout, ProgressReporter progressReporter, String versionToMigrateFrom, String versionToMigrateTo ) { RecordFormats from = RecordFormatSelector.selectForVersion( versionToMigrateFrom ); RecordFormats to = RecordFormatSelector.selectForVersion( versionToMigrateTo ); if ( !from.hasCompatibleCapabilities( to, CapabilityType.INDEX ) ) { schemaIndexDirectory = indexProvider.directoryStructure().rootDirectory(); if ( schemaIndexDirectory != null ) { deleteObsoleteIndexes = true; } // else this schema index provider doesn't have any persistent storage to delete. } }
@Override public void run( FileSystemAbstraction fs, DatabaseLayout databaseLayout ) throws IOException { int files = scrambleIndexFiles( fs, nativeIndexDirectoryStructure( databaseLayout ).rootDirectory() ); assertThat( "there is no index to sabotage", files, greaterThanOrEqualTo( 1 ) ); }
@Test public void schemaAndLabelIndexesRemovedAfterSuccessfulMigration() throws IOException { IndexDirectoryStructure directoryStructure = mock( IndexDirectoryStructure.class ); File indexProviderRootDirectory = databaseLayout.file( "just-some-directory" ); when( directoryStructure.rootDirectory() ).thenReturn( indexProviderRootDirectory ); when( indexProvider.directoryStructure() ).thenReturn( directoryStructure ); when( indexProvider.getProviderDescriptor() ) .thenReturn( new IndexProviderDescriptor( "key", "version" ) ); migrator.migrate( databaseLayout, migrationLayout, progressReporter, StandardV2_3.STORE_VERSION, StandardV3_0.STORE_VERSION ); migrator.moveMigratedFiles( migrationLayout, databaseLayout, StandardV2_3.STORE_VERSION, StandardV3_0.STORE_VERSION ); verify( fs ).deleteRecursively( indexProviderRootDirectory ); } }
private void assertCorrectDirectories( IndexDirectoryStructure directoryStructure, File expectedRootDirectory, File expectedIndexDirectory ) { // when File rootDirectory = directoryStructure.rootDirectory(); File indexDirectory = directoryStructure.directoryForIndex( indexId ); // then assertEquals( expectedRootDirectory, rootDirectory ); assertEquals( expectedIndexDirectory, indexDirectory ); } }
@Before public void setup() throws IOException, EntityNotFoundException { indexProvider = providerCreator.apply( this ); rules.fileSystem().mkdirs( indexProvider.directoryStructure().rootDirectory() ); populator = indexProvider.getPopulator( descriptor, samplingConfig ); when( nodePropertyAccessor.getNodePropertyValue( anyLong(), anyInt() ) ).thenThrow( UnsupportedOperationException.class ); prevAccessCheck = UnsafeUtil.exchangeNativeAccessCheckEnabled( false ); }
@Test void shouldCountAllIndexFiles() throws Exception { // Explicit index file File explicitIndex = testDirectory.databaseLayout().file( "explicitIndex" ); createFileOfSize( explicitIndex, 1 ); IndexImplementation indexImplementation = mock( IndexImplementation.class ); when( indexImplementation.getIndexImplementationDirectory( any() ) ).thenReturn( explicitIndex ); when( explicitIndexProviderLookup.allIndexProviders() ).thenReturn( iterable( indexImplementation ) ); // Schema index files File schemaIndex = testDirectory.databaseLayout().file( "schemaIndex" ); createFileOfSize( schemaIndex, 2 ); IndexDirectoryStructure directoryStructure = mock( IndexDirectoryStructure.class ); when( directoryStructure.rootDirectory() ).thenReturn( schemaIndex ); when( indexProvider.directoryStructure() ).thenReturn( directoryStructure ); File schemaIndex2 = testDirectory.databaseLayout().file( "schemaIndex2" ); createFileOfSize( schemaIndex2, 3 ); IndexDirectoryStructure directoryStructure2 = mock( IndexDirectoryStructure.class ); when( directoryStructure2.rootDirectory() ).thenReturn( schemaIndex2 ); when( indexProvider2.directoryStructure() ).thenReturn( directoryStructure2 ); // Label scan store File labelScan = testDirectory.databaseLayout().labelScanStore(); createFileOfSize( labelScan, 4 ); when( labelScanStore.getLabelScanStoreFile() ).thenReturn( labelScan ); // Count all files assertEquals( 10, storeSizeBean.getIndexStoreSize() ); }
private void deleteIndexFilesFor( IndexProviderDescriptor descriptor ) { File databaseDirectory = this.databaseLayout.databaseDirectory(); File rootDirectory = subProviderDirectoryStructure( databaseDirectory ).forProvider( descriptor ).rootDirectory(); File[] files = fs.listFiles( rootDirectory ); for ( File indexFile : files ) { fs.deleteFile( indexFile ); } }
@Before public void setup() throws IOException { File nativeSchemaIndexStoreDirectory = newProvider().directoryStructure().rootDirectory(); rules.fileSystem().mkdirs( nativeSchemaIndexStoreDirectory ); }
@Override public long getIndexStoreSize() { long size = 0L; // Add explicit indices for ( IndexImplementation index : explicitIndexProviderLookup.allIndexProviders() ) { size += FileUtils.size( fs, index.getIndexImplementationDirectory( databaseLayout ) ); } // Add schema index MutableLong schemaSize = new MutableLong(); indexProviderMap.accept( provider -> { File rootDirectory = provider.directoryStructure().rootDirectory(); if ( rootDirectory != null ) { schemaSize.add( FileUtils.size( fs, rootDirectory ) ); } // else this provider didn't have any persistent storage } ); size += schemaSize.longValue(); // Add label index size += FileUtils.size( fs, labelScanStore.getLabelScanStoreFile() ); return size; }
@Test public void reportNotCleanNativeIndexWithCorrectData() throws IOException, ConsistencyCheckIncompleteException { DatabaseLayout databaseLayout = db.databaseLayout(); someData(); resolveComponent( CheckPointer.class ).forceCheckPoint( new SimpleTriggerInfo( "forcedCheckpoint" ) ); File indexesCopy = databaseLayout.file( "indexesCopy" ); File indexSources = resolveComponent( DefaultIndexProviderMap.class ).getDefaultProvider().directoryStructure().rootDirectory(); copyRecursively( indexSources, indexesCopy, SOURCE_COPY_FILE_FILTER ); db.shutdownAndKeepStore(); copyRecursively( indexesCopy, indexSources ); ConsistencyCheckService.Result result = fullConsistencyCheck(); assertTrue( "Expected consistency check to fail", result.isSuccessful() ); assertThat( readReport( result ), hasItem( containsString("WARN : Index was not properly shutdown and rebuild is required.") ) ); }
@Test public void reportNotCleanNativeIndex() throws IOException, ConsistencyCheckIncompleteException { DatabaseLayout databaseLayout = db.databaseLayout(); someData(); resolveComponent( CheckPointer.class ).forceCheckPoint( new SimpleTriggerInfo( "forcedCheckpoint" ) ); File indexesCopy = databaseLayout.file( "indexesCopy" ); File indexSources = resolveComponent( DefaultIndexProviderMap.class ).getDefaultProvider().directoryStructure().rootDirectory(); copyRecursively( indexSources, indexesCopy, SOURCE_COPY_FILE_FILTER ); try ( Transaction tx = db.beginTx() ) { createNewNode( new Label[]{LABEL_ONE} ); tx.success(); } db.shutdownAndKeepStore(); copyRecursively( indexesCopy, indexSources ); ConsistencyCheckService.Result result = fullConsistencyCheck(); assertFalse( "Expected consistency check to fail", result.isSuccessful() ); assertThat( readReport( result ), hasItem( containsString("WARN : Index was not properly shutdown and rebuild is required.") ) ); }
@Override public File rootDirectory() { return parentStructure.rootDirectory(); }
@Override public void migrate( DatabaseLayout directoryLayout, DatabaseLayout migrationLayout, ProgressReporter progressReporter, String versionToMigrateFrom, String versionToMigrateTo ) { RecordFormats from = RecordFormatSelector.selectForVersion( versionToMigrateFrom ); RecordFormats to = RecordFormatSelector.selectForVersion( versionToMigrateTo ); if ( !from.hasCompatibleCapabilities( to, CapabilityType.INDEX ) ) { schemaIndexDirectory = indexProvider.directoryStructure().rootDirectory(); if ( schemaIndexDirectory != null ) { deleteObsoleteIndexes = true; } // else this schema index provider doesn't have any persistent storage to delete. } }
@Override public long getIndexStoreSize() { long size = 0L; // Add explicit indices for ( IndexImplementation index : explicitIndexProviderLookup.allIndexProviders() ) { size += FileUtils.size( fs, index.getIndexImplementationDirectory( databaseLayout ) ); } // Add schema index MutableLong schemaSize = new MutableLong(); indexProviderMap.accept( provider -> { File rootDirectory = provider.directoryStructure().rootDirectory(); if ( rootDirectory != null ) { schemaSize.add( FileUtils.size( fs, rootDirectory ) ); } // else this provider didn't have any persistent storage } ); size += schemaSize.longValue(); // Add label index size += FileUtils.size( fs, labelScanStore.getLabelScanStoreFile() ); return size; }