SpatialIndexFiles( IndexDirectoryStructure directoryStructure, long indexId, FileSystemAbstraction fs, ConfiguredSpaceFillingCurveSettingsCache settingsCache ) { this.fs = fs; this.configuredSettings = settingsCache; indexDirectory = directoryStructure.directoryForIndex( indexId ); }
@Override public File directoryForIndex( long indexId ) { return path( parentStructure.directoryForIndex( indexId ), fileNameFriendly( descriptor ) ); } };
public PartitionedIndexStorage indexStorageOf( long indexId ) { return new PartitionedIndexStorage( dirFactory, fileSystem, structure.directoryForIndex( indexId ) ); }
private File nativeIndexFileFromIndexId( long indexId ) { return new File( directoryStructure().directoryForIndex( indexId ), indexFileName( indexId ) ); }
TemporalIndexFiles( IndexDirectoryStructure directoryStructure, StoreIndexDescriptor descriptor, FileSystemAbstraction fs ) { this.fs = fs; File indexDirectory = directoryStructure.directoryForIndex( descriptor.getId() ); this.date = new FileLayout<>( new File( indexDirectory, "date" ), new DateLayout(), ValueGroup.DATE ); this.localTime = new FileLayout<>( new File( indexDirectory, "localTime" ), new LocalTimeLayout(), ValueGroup.LOCAL_TIME ); this.zonedTime = new FileLayout<>( new File( indexDirectory, "zonedTime" ), new ZonedTimeLayout(), ValueGroup.ZONED_TIME ); this.localDateTime = new FileLayout<>( new File( indexDirectory, "localDateTime" ), new LocalDateTimeLayout(), ValueGroup.LOCAL_DATE_TIME ); this.zonedDateTime = new FileLayout<>( new File( indexDirectory, "zonedDateTime" ), new ZonedDateTimeLayout(), ValueGroup.ZONED_DATE_TIME ); this.duration = new FileLayout<>( new File( indexDirectory, "duration" ), new DurationLayout(), ValueGroup.DURATION ); }
/** * Deletes index folder with the specific indexId, but has the option to first archive the index if it exists. * The zip archive will be placed next to the root directory for that index with a timestamp included in its name. * * @param fs {@link FileSystemAbstraction} this index lives in. * @param directoryStructure {@link IndexDirectoryStructure} knowing the directory structure for the provider owning the index. * @param indexId id of the index. * @param archiveIfExists whether or not to archive the index before deleting it, if it exists. * @return whether or not an archive was created. * @throws IOException on I/O error. */ public static boolean deleteIndex( FileSystemAbstraction fs, IndexDirectoryStructure directoryStructure, long indexId, boolean archiveIfExists ) throws IOException { File rootIndexDirectory = directoryStructure.directoryForIndex( indexId ); if ( archiveIfExists && fs.isDirectory( rootIndexDirectory ) && fs.fileExists( rootIndexDirectory ) && fs.listFiles( rootIndexDirectory ).length > 0 ) { ZipUtils.zip( fs, rootIndexDirectory, new File( rootIndexDirectory.getParent(), "archive-" + rootIndexDirectory.getName() + "-" + System.currentTimeMillis() + ".zip" ) ); return true; } fs.deleteRecursively( rootIndexDirectory ); return false; } }
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 ); } }
private void shouldAcceptNativeIndexFileFromFusionProvider( IndexProviderDescriptor descriptor ) throws IOException { // given File dir = subProviderDirectoryStructure( storeDir, descriptor ).forProvider( descriptor ).directoryForIndex( 1 ); File file = new File( dir, "some-file" ); createFile( file ); // when boolean accepted = filter.accept( file ); // then assertTrue( accepted ); }
@Test public void shouldNotAcceptFileFromPureLuceneProvider() throws IOException { // given File dir = directoriesByProviderKey( storeDir ).forProvider( LUCENE_DESCRTIPTOR ).directoryForIndex( 1 ); File file = new File( dir, "some-file" ); createFile( file ); // when boolean accepted = filter.accept( file ); // then assertFalse( accepted ); }
@Test public void shouldNotAcceptLuceneFileFromFusionProvider() throws IOException { // given File dir = subProviderDirectoryStructure( storeDir, LUCENE_DESCRTIPTOR ).forProvider( LUCENE_DESCRTIPTOR ).directoryForIndex( 1 ); File file = new File( dir, "some-file" ); createFile( file ); // when boolean accepted = filter.accept( file ); // then assertFalse( accepted ); }
@Test public void shouldNotLeaveNativeIndexFilesHangingAroundIfConstraintCreationFails() { // given attemptAndFailConstraintCreation(); // then IndexProvider indexProvider = db.getDependencyResolver().resolveDependency( IndexProviderMap.class ).getDefaultProvider(); File indexDir = indexProvider.directoryStructure().directoryForIndex( indexId ); assertEquals( 0, indexDir.listFiles().length ); }
@Before public void setup() throws IOException { valueCreatorUtil = createValueCreatorUtil(); indexDescriptor = valueCreatorUtil.indexDescriptor(); layout = createLayout(); indexDirectoryStructure = directoriesByProvider( directory.directory( "root" ) ).forProvider( indexDescriptor.providerDescriptor() ); indexFile = indexDirectoryStructure.directoryForIndex( indexDescriptor.getId() ); fs.mkdirs( indexFile.getParentFile() ); pageCache = pageCacheRule.getPageCache( fs ); }
@Test public void shouldNotLeaveLuceneIndexFilesHangingAroundIfConstraintCreationFails() { // given db.withSetting( default_schema_provider, NATIVE20.providerName() ); // <-- includes Lucene sub-provider attemptAndFailConstraintCreation(); // then IndexProvider indexProvider = db.getDependencyResolver().resolveDependency( IndexProviderMap.class ).getDefaultProvider(); File indexDir = indexProvider.directoryStructure().directoryForIndex( indexId ); assertFalse( new IndexFolderLayout( indexDir ).getIndexFolder().exists() ); }
@Test public void dropShouldDeleteEntireIndexFolder() { // given File root = storage.directory().directory( "root" ); IndexDirectoryStructure directoryStructure = IndexDirectoryStructure.directoriesByProvider( root ).forProvider( GenericNativeIndexProvider.DESCRIPTOR ); long indexId = 8; File indexDirectory = directoryStructure.directoryForIndex( indexId ); File indexFile = new File( indexDirectory, "my-index" ); StoreIndexDescriptor descriptor = IndexDescriptorFactory.forSchema( SchemaDescriptorFactory.forLabel( 1, 1 ) ).withId( indexId ); IndexSpecificSpaceFillingCurveSettingsCache spatialSettings = mock( IndexSpecificSpaceFillingCurveSettingsCache.class ); FileSystemAbstraction fs = storage.fileSystem(); GenericNativeIndexAccessor accessor = new GenericNativeIndexAccessor( storage.pageCache(), fs, indexFile, new GenericLayout( 1, spatialSettings ), immediate(), EMPTY, descriptor, spatialSettings, directoryStructure, mock( SpaceFillingCurveConfiguration.class ) ); // when accessor.drop(); // then assertFalse( fs.fileExists( indexDirectory ) ); } }
SpatialIndexFiles( IndexDirectoryStructure directoryStructure, long indexId, FileSystemAbstraction fs, ConfiguredSpaceFillingCurveSettingsCache settingsCache ) { this.fs = fs; this.configuredSettings = settingsCache; indexDirectory = directoryStructure.directoryForIndex( indexId ); }
@Override public File directoryForIndex( long indexId ) { return path( parentStructure.directoryForIndex( indexId ), fileNameFriendly( descriptor ) ); } };
private File nativeIndexFileFromIndexId( long indexId ) { return new File( directoryStructure().directoryForIndex( indexId ), indexFileName( indexId ) ); }
/** * Deletes index folder with the specific indexId, but has the option to first archive the index if it exists. * The zip archive will be placed next to the root directory for that index with a timestamp included in its name. * * @param fs {@link FileSystemAbstraction} this index lives in. * @param directoryStructure {@link IndexDirectoryStructure} knowing the directory structure for the provider owning the index. * @param indexId id of the index. * @param archiveIfExists whether or not to archive the index before deleting it, if it exists. * @return whether or not an archive was created. * @throws IOException on I/O error. */ public static boolean deleteIndex( FileSystemAbstraction fs, IndexDirectoryStructure directoryStructure, long indexId, boolean archiveIfExists ) throws IOException { File rootIndexDirectory = directoryStructure.directoryForIndex( indexId ); if ( archiveIfExists && fs.isDirectory( rootIndexDirectory ) && fs.fileExists( rootIndexDirectory ) && fs.listFiles( rootIndexDirectory ).length > 0 ) { ZipUtils.zip( fs, rootIndexDirectory, new File( rootIndexDirectory.getParent(), "archive-" + rootIndexDirectory.getName() + "-" + System.currentTimeMillis() + ".zip" ) ); return true; } fs.deleteRecursively( rootIndexDirectory ); return false; } }
TemporalIndexFiles( IndexDirectoryStructure directoryStructure, StoreIndexDescriptor descriptor, FileSystemAbstraction fs ) { this.fs = fs; File indexDirectory = directoryStructure.directoryForIndex( descriptor.getId() ); this.date = new FileLayout<>( new File( indexDirectory, "date" ), new DateLayout(), ValueGroup.DATE ); this.localTime = new FileLayout<>( new File( indexDirectory, "localTime" ), new LocalTimeLayout(), ValueGroup.LOCAL_TIME ); this.zonedTime = new FileLayout<>( new File( indexDirectory, "zonedTime" ), new ZonedTimeLayout(), ValueGroup.ZONED_TIME ); this.localDateTime = new FileLayout<>( new File( indexDirectory, "localDateTime" ), new LocalDateTimeLayout(), ValueGroup.LOCAL_DATE_TIME ); this.zonedDateTime = new FileLayout<>( new File( indexDirectory, "zonedDateTime" ), new ZonedDateTimeLayout(), ValueGroup.ZONED_DATE_TIME ); this.duration = new FileLayout<>( new File( indexDirectory, "duration" ), new DurationLayout(), ValueGroup.DURATION ); }