Search in sources :

Example 21 with DefaultIdGeneratorFactory

use of org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory in project neo4j by neo4j.

the class CommonAbstractStoreTest method recordCursorPinsEachPageItReads.

@Test
public void recordCursorPinsEachPageItReads() throws Exception {
    File storeFile = dir.file("a");
    RecordingPageCacheTracer tracer = new RecordingPageCacheTracer();
    RecordingPageCursorTracer pageCursorTracer = new RecordingPageCursorTracer(Pin.class);
    PageCacheRule.PageCacheConfig pageCacheConfig = config().withTracer(tracer).withCursorTracerSupplier(pageCursorTracerSupplier(pageCursorTracer));
    PageCache pageCache = pageCacheRule.getPageCache(fileSystemRule.get(), pageCacheConfig, Config.empty());
    try (NodeStore store = new NodeStore(storeFile, Config.empty(), new DefaultIdGeneratorFactory(fileSystemRule.get()), pageCache, NullLogProvider.getInstance(), null, Standard.LATEST_RECORD_FORMATS)) {
        store.initialise(true);
        assertNull(tracer.tryObserve(Event.class));
        long nodeId1 = insertNodeRecordAndObservePinEvent(pageCursorTracer, store);
        long nodeId2 = insertNodeRecordAndObservePinEvent(pageCursorTracer, store);
        try (RecordCursor<NodeRecord> cursor = store.newRecordCursor(store.newRecord())) {
            cursor.acquire(0, RecordLoad.NORMAL);
            assertTrue(cursor.next(nodeId1));
            assertTrue(cursor.next(nodeId2));
        }
        // Because both nodes hit the same page, the code will only pin the page once and thus only emit one pin
        // event. This pin event will not be observable until after we have closed the cursor. We could
        // alternatively have chosen nodeId2 to be on a different page than nodeId1. In that case, the pin event
        // for nodeId1 would have been visible after our call to cursor.next( nodeId2 ).
        assertNotNull(pageCursorTracer.tryObserve(Pin.class));
        assertNull(pageCursorTracer.tryObserve(Event.class));
    }
}
Also used : DefaultIdGeneratorFactory(org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory) RecordingPageCacheTracer(org.neo4j.io.pagecache.tracing.recording.RecordingPageCacheTracer) RecordingPageCursorTracer(org.neo4j.io.pagecache.tracing.recording.RecordingPageCursorTracer) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) Pin(org.neo4j.io.pagecache.tracing.recording.RecordingPageCursorTracer.Pin) Event(org.neo4j.io.pagecache.tracing.recording.Event) PagedFile(org.neo4j.io.pagecache.PagedFile) File(java.io.File) ConfigurablePageCacheRule(org.neo4j.test.rule.ConfigurablePageCacheRule) PageCacheRule(org.neo4j.test.rule.PageCacheRule) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Example 22 with DefaultIdGeneratorFactory

use of org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory in project neo4j by neo4j.

the class NeoStoresTest method impossibleToGetStoreFromClosedNeoStoresContainer.

@Test
public void impossibleToGetStoreFromClosedNeoStoresContainer() {
    Config config = Config.embeddedDefaults();
    StoreFactory sf = new StoreFactory(storeDir, config, new DefaultIdGeneratorFactory(fs.get()), pageCache, fs.get(), NullLogProvider.getInstance());
    NeoStores neoStores = sf.openAllNeoStores(true);
    assertNotNull(neoStores.getMetaDataStore());
    neoStores.close();
    exception.expect(IllegalStateException.class);
    exception.expectMessage("Specified store was already closed.");
    neoStores.getMetaDataStore();
}
Also used : Config(org.neo4j.kernel.configuration.Config) DefaultIdGeneratorFactory(org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory) Test(org.junit.Test)

Example 23 with DefaultIdGeneratorFactory

use of org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory in project neo4j by neo4j.

the class NeoStoresTest method setVersion.

@Test
public void setVersion() throws Exception {
    FileSystemAbstraction fileSystem = fs.get();
    File storeDir = new File("target/test-data/set-version").getAbsoluteFile();
    createTestDatabase(fileSystem, storeDir).shutdown();
    assertEquals(0, MetaDataStore.setRecord(pageCache, new File(storeDir, MetaDataStore.DEFAULT_NAME).getAbsoluteFile(), Position.LOG_VERSION, 10));
    assertEquals(10, MetaDataStore.setRecord(pageCache, new File(storeDir, MetaDataStore.DEFAULT_NAME).getAbsoluteFile(), Position.LOG_VERSION, 12));
    Config config = Config.embeddedDefaults();
    StoreFactory sf = new StoreFactory(storeDir, config, new DefaultIdGeneratorFactory(fileSystem), pageCache, fileSystem, NullLogProvider.getInstance());
    NeoStores neoStores = sf.openAllNeoStores();
    assertEquals(12, neoStores.getMetaDataStore().getCurrentLogVersion());
    neoStores.close();
}
Also used : UncloseableDelegatingFileSystemAbstraction(org.neo4j.graphdb.mockfs.UncloseableDelegatingFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Config(org.neo4j.kernel.configuration.Config) DefaultIdGeneratorFactory(org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory) File(java.io.File) Test(org.junit.Test)

Example 24 with DefaultIdGeneratorFactory

use of org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory in project neo4j by neo4j.

the class NeoStoresTest method impossibleToGetNotRequestedStore.

@Test
public void impossibleToGetNotRequestedStore() {
    Config config = Config.embeddedDefaults();
    StoreFactory sf = new StoreFactory(storeDir, config, new DefaultIdGeneratorFactory(fs.get()), pageCache, fs.get(), NullLogProvider.getInstance());
    NeoStores neoStores = sf.openNeoStores(true, StoreType.NODE_LABEL);
    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.getMetaDataStore();
    } finally {
        neoStores.close();
    }
}
Also used : Config(org.neo4j.kernel.configuration.Config) DefaultIdGeneratorFactory(org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory) Test(org.junit.Test)

Example 25 with DefaultIdGeneratorFactory

use of org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory in project neo4j by neo4j.

the class NeoStoresTest method testSetLatestConstraintTx.

@Test
public void testSetLatestConstraintTx() throws Exception {
    // given
    Config config = Config.embeddedDefaults();
    StoreFactory sf = new StoreFactory(dir.directory(), config, new DefaultIdGeneratorFactory(fs.get()), pageCacheRule.getPageCache(fs.get()), fs.get(), NullLogProvider.getInstance());
    // when
    NeoStores neoStores = sf.openAllNeoStores(true);
    MetaDataStore metaDataStore = neoStores.getMetaDataStore();
    // then the default is 0
    assertEquals(0L, metaDataStore.getLatestConstraintIntroducingTx());
    // when
    metaDataStore.setLatestConstraintIntroducingTx(10L);
    // then
    assertEquals(10L, metaDataStore.getLatestConstraintIntroducingTx());
    // when
    neoStores.flush(IOLimiter.unlimited());
    neoStores.close();
    neoStores = sf.openAllNeoStores();
    // then the value should have been stored
    assertEquals(10L, neoStores.getMetaDataStore().getLatestConstraintIntroducingTx());
    neoStores.close();
}
Also used : Config(org.neo4j.kernel.configuration.Config) DefaultIdGeneratorFactory(org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory) Test(org.junit.Test)

Aggregations

DefaultIdGeneratorFactory (org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory)34 File (java.io.File)18 Config (org.neo4j.kernel.configuration.Config)17 Test (org.junit.Test)13 StoreFactory (org.neo4j.kernel.impl.store.StoreFactory)11 Before (org.junit.Before)10 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)8 PageCache (org.neo4j.io.pagecache.PageCache)6 NeoStores (org.neo4j.kernel.impl.store.NeoStores)5 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)4 ArrayList (java.util.ArrayList)3 UncloseableDelegatingFileSystemAbstraction (org.neo4j.graphdb.mockfs.UncloseableDelegatingFileSystemAbstraction)2 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)2 PagedFile (org.neo4j.io.pagecache.PagedFile)2 StandalonePageCacheFactory.createPageCache (org.neo4j.io.pagecache.impl.muninn.StandalonePageCacheFactory.createPageCache)2 DynamicRecord (org.neo4j.kernel.impl.store.record.DynamicRecord)2 NullLogProvider (org.neo4j.logging.NullLogProvider)2 IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 PrintStream (java.io.PrintStream)1