Search in sources :

Example 41 with DefaultIdGeneratorFactory

use of org.neo4j.internal.id.DefaultIdGeneratorFactory in project neo4j by neo4j.

the class NeoStoreOpenFailureTest method mustCloseAllStoresIfNeoStoresFailToOpen.

@Test
@DisabledForRoot
void mustCloseAllStoresIfNeoStoresFailToOpen() {
    Config config = Config.defaults();
    IdGeneratorFactory idGenFactory = new DefaultIdGeneratorFactory(fileSystem, immediate(), databaseLayout.getDatabaseName());
    LogProvider logProvider = NullLogProvider.getInstance();
    RecordFormats formats = Standard.LATEST_RECORD_FORMATS;
    RecordFormatPropertyConfigurator.configureRecordFormat(formats, config);
    boolean create = true;
    StoreType[] storeTypes = StoreType.values();
    ImmutableSet<OpenOption> openOptions = immutable.empty();
    NeoStores neoStores = new NeoStores(fileSystem, databaseLayout, config, idGenFactory, pageCache, logProvider, formats, create, NULL, writable(), storeTypes, openOptions);
    Path schemaStore = neoStores.getSchemaStore().getStorageFile();
    neoStores.close();
    // Make the schema store inaccessible, to sabotage the next initialisation we'll do.
    assumeTrue(schemaStore.toFile().setReadable(false));
    assumeTrue(schemaStore.toFile().setWritable(false));
    assertThrows(RuntimeException.class, () -> new NeoStores(fileSystem, databaseLayout, config, idGenFactory, pageCache, logProvider, formats, create, NULL, writable(), storeTypes, openOptions));
    // We verify that the successfully opened stores were closed again by the failed NeoStores open,
    // by closing the page cache, which will throw if not all files have been unmapped.
    pageCache.close();
}
Also used : Path(java.nio.file.Path) LogProvider(org.neo4j.logging.LogProvider) NullLogProvider(org.neo4j.logging.NullLogProvider) OpenOption(java.nio.file.OpenOption) RecordFormats(org.neo4j.kernel.impl.store.format.RecordFormats) Config(org.neo4j.configuration.Config) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) IdGeneratorFactory(org.neo4j.internal.id.IdGeneratorFactory) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) Test(org.junit.jupiter.api.Test) DisabledForRoot(org.neo4j.test.extension.DisabledForRoot)

Example 42 with DefaultIdGeneratorFactory

use of org.neo4j.internal.id.DefaultIdGeneratorFactory in project neo4j by neo4j.

the class NodeStoreTest method newNodeStore.

private NodeStore newNodeStore(FileSystemAbstraction fs, PageCache pageCache) {
    IdGeneratorFactory idGeneratorFactory = spy(new DefaultIdGeneratorFactory(fs, immediate(), databaseLayout.getDatabaseName()) {

        @Override
        protected IndexedIdGenerator instantiate(FileSystemAbstraction fs, PageCache pageCache, RecoveryCleanupWorkCollector recoveryCleanupWorkCollector, Path fileName, LongSupplier highIdSupplier, long maxValue, IdType idType, DatabaseReadOnlyChecker readOnlyChecker, Config config, CursorContext cursorContext, String databaseName, ImmutableSet<OpenOption> openOptions) {
            return spy(super.instantiate(fs, pageCache, recoveryCleanupWorkCollector, fileName, highIdSupplier, maxValue, idType, readOnlyChecker, config, cursorContext, databaseName, openOptions));
        }
    });
    StoreFactory factory = new StoreFactory(databaseLayout, Config.defaults(), idGeneratorFactory, pageCache, fs, NullLogProvider.getInstance(), PageCacheTracer.NULL, writable());
    neoStores = factory.openAllNeoStores(true);
    nodeStore = neoStores.getNodeStore();
    return nodeStore;
}
Also used : Path(java.nio.file.Path) EphemeralFileSystemAbstraction(org.neo4j.io.fs.EphemeralFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) IndexedIdGenerator(org.neo4j.internal.id.indexed.IndexedIdGenerator) Config(org.neo4j.configuration.Config) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) IdGeneratorFactory(org.neo4j.internal.id.IdGeneratorFactory) CursorContext(org.neo4j.io.pagecache.context.CursorContext) StringContains.containsString(org.hamcrest.core.StringContains.containsString) RecoveryCleanupWorkCollector(org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector) IdType(org.neo4j.internal.id.IdType) OpenOption(java.nio.file.OpenOption) DatabaseReadOnlyChecker(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker) LongSupplier(java.util.function.LongSupplier) PageCache(org.neo4j.io.pagecache.PageCache) DelegatingPageCache(org.neo4j.io.pagecache.DelegatingPageCache)

Example 43 with DefaultIdGeneratorFactory

use of org.neo4j.internal.id.DefaultIdGeneratorFactory in project neo4j by neo4j.

the class CommonAbstractStoreTest method shouldDeleteOnCloseIfOpenOptionsSaysSo.

@Test
void shouldDeleteOnCloseIfOpenOptionsSaysSo() throws IOException {
    // GIVEN
    Path nodeStore = databaseLayout.nodeStore();
    Path idFile = databaseLayout.idFile(DatabaseFile.NODE_STORE).orElseThrow(() -> new IllegalStateException("Node store id file not found."));
    TheStore store = new TheStore(nodeStore, databaseLayout.idNodeStore(), config, idType, new DefaultIdGeneratorFactory(fs, immediate(), databaseLayout.getDatabaseName()), pageCache, NullLogProvider.getInstance(), recordFormat, immutable.with(DELETE_ON_CLOSE));
    store.initialise(true, NULL);
    store.start(NULL);
    assertTrue(fs.fileExists(nodeStore));
    assertTrue(fs.fileExists(idFile));
    // WHEN
    store.close();
    // THEN
    assertFalse(fs.fileExists(nodeStore));
    assertFalse(fs.fileExists(idFile));
}
Also used : Path(java.nio.file.Path) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) Test(org.junit.jupiter.api.Test)

Example 44 with DefaultIdGeneratorFactory

use of org.neo4j.internal.id.DefaultIdGeneratorFactory in project neo4j by neo4j.

the class MetaDataStoreTest method newMetaDataStore.

private MetaDataStore newMetaDataStore(PageCacheTracer pageCacheTracer) {
    LogProvider logProvider = NullLogProvider.getInstance();
    StoreFactory storeFactory = new StoreFactory(databaseLayout, Config.defaults(), new DefaultIdGeneratorFactory(fs, immediate(), databaseLayout.getDatabaseName()), pageCacheWithFakeOverflow, fs, logProvider, pageCacheTracer, writable());
    return storeFactory.openNeoStores(true, StoreType.META_DATA).getMetaDataStore();
}
Also used : NullLogProvider(org.neo4j.logging.NullLogProvider) LogProvider(org.neo4j.logging.LogProvider) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory)

Example 45 with DefaultIdGeneratorFactory

use of org.neo4j.internal.id.DefaultIdGeneratorFactory in project neo4j by neo4j.

the class PropertyStoreTest method shouldWriteOutTheDynamicChainBeforeUpdatingThePropertyRecord.

@Test
void shouldWriteOutTheDynamicChainBeforeUpdatingThePropertyRecord() throws IOException {
    // given
    try (PageCache pageCache = pageCacheExtension.getPageCache(fs)) {
        Config config = Config.defaults();
        DynamicStringStore stringPropertyStore = mock(DynamicStringStore.class);
        try (var store = new PropertyStore(storeFile, idFile, config, new DefaultIdGeneratorFactory(fs, immediate(), databaseLayout.getDatabaseName()), pageCache, NullLogProvider.getInstance(), stringPropertyStore, mock(PropertyKeyTokenStore.class), mock(DynamicArrayStore.class), RecordFormatSelector.defaultFormat(), writable(), databaseLayout.getDatabaseName(), immutable.empty())) {
            store.initialise(true, NULL);
            store.start(NULL);
            final long propertyRecordId = store.nextId(NULL);
            PropertyRecord record = new PropertyRecord(propertyRecordId);
            record.setInUse(true);
            DynamicRecord dynamicRecord = dynamicRecord();
            PropertyBlock propertyBlock = propertyBlockWith(dynamicRecord);
            record.setPropertyBlock(propertyBlock);
            doAnswer(invocation -> {
                PropertyRecord recordBeforeWrite = store.getRecord(propertyRecordId, store.newRecord(), FORCE, NULL);
                assertFalse(recordBeforeWrite.inUse());
                return null;
            }).when(stringPropertyStore).updateRecord(eq(dynamicRecord), any());
            // when
            store.updateRecord(record, NULL);
            // then verify that our mocked method above, with the assert, was actually called
            verify(stringPropertyStore).updateRecord(eq(dynamicRecord), any(), any());
        }
    }
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) Config(org.neo4j.configuration.Config) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.jupiter.api.Test)

Aggregations

DefaultIdGeneratorFactory (org.neo4j.internal.id.DefaultIdGeneratorFactory)53 StoreFactory (org.neo4j.kernel.impl.store.StoreFactory)29 BeforeEach (org.junit.jupiter.api.BeforeEach)20 Config (org.neo4j.configuration.Config)18 Test (org.junit.jupiter.api.Test)15 NeoStores (org.neo4j.kernel.impl.store.NeoStores)14 Path (java.nio.file.Path)10 PageCache (org.neo4j.io.pagecache.PageCache)10 NullLogProvider (org.neo4j.logging.NullLogProvider)10 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)9 CursorContext (org.neo4j.io.pagecache.context.CursorContext)9 IdGeneratorFactory (org.neo4j.internal.id.IdGeneratorFactory)8 IOException (java.io.IOException)7 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)6 RecordFormats (org.neo4j.kernel.impl.store.format.RecordFormats)6 TokenHolders (org.neo4j.token.TokenHolders)6 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)5 DatabaseReadOnlyChecker.writable (org.neo4j.configuration.helpers.DatabaseReadOnlyChecker.writable)5 RecoveryCleanupWorkCollector.immediate (org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector.immediate)5 ArrayList (java.util.ArrayList)4