/** * Opens the {@link IdGenerator} used by this store. * <p> * Note: This method may be called both while the store has the store file mapped in the * page cache, and while the store file is not mapped. Implementers must therefore * map their own temporary PagedFile for the store file, and do their file IO through that, * if they need to access the data in the store file. */ void openIdGenerator() { idGenerator = idGeneratorFactory.open( idFile, getIdType(), this::scanForHighId, recordFormat.getMaxId() ); }
@Before public void setUpMocks() throws IOException { when( idGeneratorFactory.open( any( File.class ), eq( idType ), any( LongSupplier.class ), anyLong() ) ) .thenReturn( idGenerator ); when( pageFile.pageSize() ).thenReturn( PAGE_SIZE ); when( pageFile.io( anyLong(), anyInt() ) ).thenReturn( pageCursor ); when( pageCache.map( eq( storeFile ), anyInt() ) ).thenReturn( pageFile ); }
@Override public IdGenerator open( File filename, int grabSize, IdType idType, LongSupplier highId, long maxId ) { assert boundaries != null : "Factory needs to be initialized before usage"; IdGenerator generator = delegate.open( filename, grabSize, idType, highId, maxId ); IdTypeConfiguration typeConfiguration = getIdTypeConfiguration(idType); if ( typeConfiguration.allowAggressiveReuse() ) { BufferingIdGenerator bufferingGenerator = new BufferingIdGenerator( generator ); bufferingGenerator.initialize( boundaries, safeThreshold ); overriddenIdGenerators[idType.ordinal()] = bufferingGenerator; generator = bufferingGenerator; } return generator; }
@Test void createContextWithCustomIdGeneratorFactoryWhenProvided() { IdGeneratorFactory idGeneratorFactory = mock( IdGeneratorFactory.class ); IdContextFactory contextFactory = IdContextFactoryBuilder.of( fs, jobScheduler ).withIdGenerationFactoryProvider( any -> idGeneratorFactory ).build(); DatabaseIdContext idContext = contextFactory.createIdContext( "database" ); IdGeneratorFactory bufferedGeneratorFactory = idContext.getIdGeneratorFactory(); assertThat( idContext.getIdController(), instanceOf( BufferedIdController.class ) ); assertThat( bufferedGeneratorFactory, instanceOf( BufferingIdGeneratorFactory.class ) ); ((BufferingIdGeneratorFactory)bufferedGeneratorFactory).initialize( () -> mock( KernelTransactionsSnapshot.class ) ); File file = testDirectory.file( "a" ); IdType idType = IdType.NODE; LongSupplier highIdSupplier = () -> 0; int maxId = 100; idGeneratorFactory.open( file, idType, highIdSupplier, maxId ); verify( idGeneratorFactory ).open( file, idType, highIdSupplier, maxId ); }
@Test void createCommunityBufferedContextByDefault() { IdContextFactory idContextFactory = IdContextFactoryBuilder.of( fs, jobScheduler ).build(); DatabaseIdContext idContext = idContextFactory.createIdContext( "database" ); IdGeneratorFactory idGeneratorFactory = idContext.getIdGeneratorFactory(); assertThat( idContext.getIdController(), instanceOf( BufferedIdController.class ) ); assertThat( idGeneratorFactory, instanceOf( BufferingIdGeneratorFactory.class ) ); ((BufferingIdGeneratorFactory)idGeneratorFactory).initialize( () -> mock( KernelTransactionsSnapshot.class ) ); idGeneratorFactory.open( testDirectory.file( "a"), IdType.NODE, () -> 0, 100 ).close(); idGeneratorFactory.open( testDirectory.file( "b"), IdType.PROPERTY, () -> 0, 100 ).close(); BufferingIdGeneratorFactory bufferedFactory = (BufferingIdGeneratorFactory) idGeneratorFactory; assertThat( bufferedFactory.get( IdType.NODE ), instanceOf( IdGeneratorImpl.class ) ); assertThat( bufferedFactory.get( IdType.PROPERTY ), not( instanceOf( IdGeneratorImpl.class ) ) ); }
@Override public IdGenerator open( File filename, IdType idType, LongSupplier highId, long maxId ) { FreeIdFilteredIdGenerator freeIdFilteredIdGenerator = new FreeIdFilteredIdGenerator( delegate.open( filename, idType, highId, maxId ), freeIdCondition ); delegatedGenerator.put( idType, freeIdFilteredIdGenerator ); return freeIdFilteredIdGenerator; }
@Override public IdGenerator open( File filename, int grabSize, IdType idType, LongSupplier highId, long maxId ) { FreeIdFilteredIdGenerator freeIdFilteredIdGenerator = new FreeIdFilteredIdGenerator( delegate.open( filename, grabSize, idType, highId, maxId ), freeIdCondition ); delegatedGenerator.put( idType, freeIdFilteredIdGenerator ); return freeIdFilteredIdGenerator; }
/** * Opens the {@link IdGenerator} used by this store. * <p> * Note: This method may be called both while the store has the store file mapped in the * page cache, and while the store file is not mapped. Implementers must therefore * map their own temporary PagedFile for the store file, and do their file IO through that, * if they need to access the data in the store file. */ void openIdGenerator() { idGenerator = idGeneratorFactory.open( idFile, getIdType(), this::scanForHighId, recordFormat.getMaxId() ); }
@Override public IdGenerator open( File filename, int grabSize, IdType idType, LongSupplier highId, long maxId ) { assert boundaries != null : "Factory needs to be initialized before usage"; IdGenerator generator = delegate.open( filename, grabSize, idType, highId, maxId ); IdTypeConfiguration typeConfiguration = getIdTypeConfiguration(idType); if ( typeConfiguration.allowAggressiveReuse() ) { BufferingIdGenerator bufferingGenerator = new BufferingIdGenerator( generator ); bufferingGenerator.initialize( boundaries, safeThreshold ); overriddenIdGenerators[idType.ordinal()] = bufferingGenerator; generator = bufferingGenerator; } return generator; }