private void deleteStoreFiles( DatabaseLayout databaseLayout, Predicate<StoreType> storesToKeep ) { for ( StoreType type : StoreType.values() ) { if ( type.isRecordStore() && !storesToKeep.test( type ) ) { DatabaseFile databaseFile = type.getDatabaseFile(); databaseLayout.file( databaseFile ).forEach( fileSystem::deleteFile ); databaseLayout.idFile( databaseFile ).ifPresent( fileSystem::deleteFile ); } } }
/** * Returns specified store by type from already opened store array. If store is not opened exception will be * thrown. * * @see #getOrCreateStore * @param storeType store type to retrieve * @return store of requested type * @throws IllegalStateException if opened store not found */ private Object getStore( StoreType storeType ) { Object store = stores[storeType.ordinal()]; if ( store == null ) { String message = ArrayUtil.contains( initializedStores, storeType ) ? STORE_ALREADY_CLOSED_MESSAGE : String.format( STORE_NOT_INITIALIZED_TEMPLATE, storeType.name() ); throw new IllegalStateException( message ); } return store; }
@Test public void storeTypeOfMetaDataStoreFile() { StoreType matchedType = StoreType.typeOf( DatabaseFile.METADATA_STORE ).orElseThrow( () -> new IllegalStateException( "Store type not found" ) ); assertEquals( StoreType.META_DATA, matchedType ); }
@Override public boolean test( StoreType type ) { return type.isRecordStore() && stores[type.ordinal()] != null; } };
public RenewableBatchIdSequences( NeoStores stores, int batchSize ) { for ( StoreType type : StoreType.values() ) { if ( type.isRecordStore() ) { RecordStore<AbstractBaseRecord> store = stores.getRecordStore( type ); if ( type.isLimitedIdStore() || batchSize == 1 ) { // This is a token store or otherwise meta-data store, so let's not add batching for it types[type.ordinal()] = store; } else { // This is a normal record store where id batching is beneficial types[type.ordinal()] = new RenewableBatchIdSequence( store, batchSize, store::freeId ); } } } }
/** * Open {@link NeoStores} with all possible stores. If some store does not exist it will <b>not</b> be created. * @return container with all opened stores */ public NeoStores openAllNeoStores() { return openNeoStores( false, StoreType.values() ); }
/** * Determine type of a store base on provided database file. * * @param databaseFile - database file to map * @return an {@link Optional} that wraps the matching store type of the specified file, * or {@link Optional#empty()} if the given file name does not match any store files. */ public static Optional<StoreType> typeOf( DatabaseFile databaseFile ) { Objects.requireNonNull( databaseFile ); StoreType[] values = StoreType.values(); for ( StoreType value : values ) { if ( value.getDatabaseFile().equals( databaseFile ) ) { return Optional.of( value ); } } return Optional.empty(); } }
private StoreType[] relevantRecordStores() { return Stream.of( StoreType.values() ) .filter( type -> type.isRecordStore() && type != StoreType.META_DATA ).toArray( StoreType[]::new ); }
private void flushIdFiles( NeoStores neoStores, StoreType[] storeTypes ) { for ( StoreType type : storeTypes ) { if ( type.isRecordStore() ) { RecordStore<AbstractBaseRecord> recordStore = neoStores.getRecordStore( type ); Optional<File> idFile = databaseLayout.idFile( type.getDatabaseFile() ); idFile.ifPresent( f -> idGeneratorFactory.create( f, recordStore.getHighId(), false ) ); } } } }
@Override public Collection<StoreFileMetadata> listStorageFiles() { List<StoreFileMetadata> files = new ArrayList<>(); for ( StoreType type : StoreType.values() ) { if ( type.equals( StoreType.COUNTS ) ) { addCountStoreFiles( files ); } else { final RecordStore<AbstractBaseRecord> recordStore = neoStores.getRecordStore( type ); StoreFileMetadata metadata = new StoreFileMetadata( recordStore.getStorageFile(), recordStore.getRecordSize() ); files.add( metadata ); } } return files; }
@SuppressWarnings( "unchecked" ) public <RECORD extends AbstractBaseRecord> RecordStore<RECORD> getRecordStore( StoreType type ) { assert type.isRecordStore(); return (RecordStore<RECORD>) getStore( type ); }
private boolean hasStoreFiles() { for ( StoreType storeType : StoreType.values() ) { StoreFile storeFile = storeType.getStoreFile(); if(storeFile != null) { boolean exists = fileSystemAbstraction.fileExists( new File( storeDir, storeFile.storeFileName() ) ); if ( exists ) { return true; } } } return false; }
if ( !pageCache.fileSystemSupportsFileOperations() && StoreType.canBeManagedByPageCache( file.getName() ) )
@Test public void impossibleToGetNotRequestedStore() { Config config = Config.defaults(); StoreFactory sf = getStoreFactory( config, databaseLayout, fs.get(), NullLogProvider.getInstance() ); exception.expect( IllegalStateException.class ); exception.expectMessage( "Specified store was not initialized. Please specify " + StoreType.META_DATA.name() + " as one of the stores types that should be open to be able to use it." ); try ( NeoStores neoStores = sf.openNeoStores( true, StoreType.NODE_LABEL ) ) { neoStores.getMetaDataStore(); } }
/** * Open {@link NeoStores} with all possible stores with a possibility to create store if it not exist. * @param createStoreIfNotExists - should store be created if it's not exist * @return container with all opened stores */ public NeoStores openAllNeoStores( boolean createStoreIfNotExists ) { return openNeoStores( createStoreIfNotExists, StoreType.values() ); }
private void manuallyCountTotalMappedFileSize( File dir, MutableLong result, NativeIndexFileFilter nativeIndexFilter ) { Set<String> storeFiles = Stream.of( StoreType.values() ).filter( StoreType::isRecordStore ).map( type -> type.getDatabaseFile().getName() ).collect( Collectors.toSet() ); for ( File file : dir.listFiles() ) { if ( file.isDirectory() ) { manuallyCountTotalMappedFileSize( file, result, nativeIndexFilter ); } else if ( storeFiles.contains( file.getName() ) || file.getName().equals( DatabaseFile.LABEL_SCAN_STORE.getName() ) || nativeIndexFilter.accept( file ) ) { result.add( file.length() ); } } }
public RenewableBatchIdSequences( NeoStores stores, int batchSize ) { for ( StoreType type : StoreType.values() ) { if ( type.isRecordStore() ) { RecordStore<AbstractBaseRecord> store = stores.getRecordStore( type ); if ( type.isLimitedIdStore() || batchSize == 1 ) { // This is a token store or otherwise meta-data store, so let's not add batching for it types[type.ordinal()] = store; } else { // This is a normal record store where id batching is beneficial types[type.ordinal()] = new RenewableBatchIdSequence( store, batchSize, store::freeId ); } } } }
private static void assertSameStoreContents( EphemeralFileSystemAbstraction fs1, EphemeralFileSystemAbstraction fs2, DatabaseLayout databaseLayout ) { NullLogProvider logProvider = NullLogProvider.getInstance(); VersionContextSupplier contextSupplier = EmptyVersionContextSupplier.EMPTY; try ( ThreadPoolJobScheduler jobScheduler = new ThreadPoolJobScheduler(); PageCache pageCache1 = new ConfiguringPageCacheFactory( fs1, defaults(), PageCacheTracer.NULL, PageCursorTracerSupplier.NULL, NullLog.getInstance(), contextSupplier, jobScheduler ) .getOrCreatePageCache(); PageCache pageCache2 = new ConfiguringPageCacheFactory( fs2, defaults(), PageCacheTracer.NULL, PageCursorTracerSupplier.NULL, NullLog.getInstance(), contextSupplier, jobScheduler ) .getOrCreatePageCache(); NeoStores store1 = new StoreFactory( databaseLayout, defaults(), new DefaultIdGeneratorFactory( fs1 ), pageCache1, fs1, logProvider, contextSupplier ).openAllNeoStores(); NeoStores store2 = new StoreFactory( databaseLayout, defaults(), new DefaultIdGeneratorFactory( fs2 ), pageCache2, fs2, logProvider, contextSupplier ).openAllNeoStores() ) { for ( StoreType storeType : StoreType.values() ) { if ( storeType.isRecordStore() ) { assertSameStoreContents( store1.getRecordStore( storeType ), store2.getRecordStore( storeType ) ); } } } }
private void flushIdFiles( NeoStores neoStores, StoreType[] storeTypes ) { for ( StoreType type : storeTypes ) { if ( type.isRecordStore() ) { RecordStore<AbstractBaseRecord> recordStore = neoStores.getRecordStore( type ); Optional<File> idFile = databaseLayout.idFile( type.getDatabaseFile() ); idFile.ifPresent( f -> idGeneratorFactory.create( f, recordStore.getHighId(), false ) ); } } } }
@Override public Collection<StoreFileMetadata> listStorageFiles() { List<StoreFileMetadata> files = new ArrayList<>(); for ( StoreType type : StoreType.values() ) { if ( type.equals( StoreType.COUNTS ) ) { addCountStoreFiles( files ); } else { final RecordStore<AbstractBaseRecord> recordStore = neoStores.getRecordStore( type ); StoreFileMetadata metadata = new StoreFileMetadata( recordStore.getStorageFile(), recordStore.getRecordSize() ); files.add( metadata ); } } return files; }