Search in sources :

Example 11 with MetaDataStore

use of org.neo4j.kernel.impl.store.MetaDataStore in project neo4j by neo4j.

the class CountsStoreRecoveryTest method flushNeoStoreOnly.

private void flushNeoStoreOnly() throws Exception {
    NeoStores neoStores = ((GraphDatabaseAPI) db).getDependencyResolver().resolveDependency(RecordStorageEngine.class).testAccessNeoStores();
    MetaDataStore metaDataStore = neoStores.getMetaDataStore();
    metaDataStore.flush();
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) RecordStorageEngine(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine) MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore) NeoStores(org.neo4j.kernel.impl.store.NeoStores)

Example 12 with MetaDataStore

use of org.neo4j.kernel.impl.store.MetaDataStore in project neo4j by neo4j.

the class IntegrityValidatorTest method tokenIndexesNotAllowedForOldKernelVersions.

@Test
void tokenIndexesNotAllowedForOldKernelVersions() {
    // Given
    NeoStores store = mock(NeoStores.class);
    MetaDataStore metaDataStore = mock(MetaDataStore.class);
    when(store.getMetaDataStore()).thenReturn(metaDataStore);
    when(metaDataStore.kernelVersion()).thenReturn(KernelVersion.V4_2);
    IndexUpdateListener indexes = mock(IndexUpdateListener.class);
    IntegrityValidator validator = new IntegrityValidator(store);
    validator.setIndexValidator(indexes);
    var index = IndexPrototype.forSchema(SchemaDescriptor.forAnyEntityTokens(EntityType.NODE)).withIndexType(IndexType.LOOKUP).withName("any name").materialise(4);
    // When
    assertThatThrownBy(() -> validator.validateSchemaRule(index)).isInstanceOf(TransactionFailureException.class).hasMessageContaining("Required kernel version for this transaction is V4_3_D4, but actual version was V4_2.");
}
Also used : TransactionFailureException(org.neo4j.internal.kernel.api.exceptions.TransactionFailureException) MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore) NeoStores(org.neo4j.kernel.impl.store.NeoStores) IndexUpdateListener(org.neo4j.storageengine.api.IndexUpdateListener) Test(org.junit.jupiter.api.Test)

Example 13 with MetaDataStore

use of org.neo4j.kernel.impl.store.MetaDataStore in project neo4j by neo4j.

the class DatabaseUpgradeTransactionIT method setKernelVersion.

private void setKernelVersion(KernelVersion version) {
    MetaDataStore metaDataStore = db.getDependencyResolver().resolveDependency(MetaDataStore.class);
    metaDataStore.setKernelVersion(version, CursorContext.NULL);
}
Also used : MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore)

Example 14 with MetaDataStore

use of org.neo4j.kernel.impl.store.MetaDataStore in project neo4j by neo4j.

the class DatabaseStartupTest method startTheDatabaseWithWrongVersionShouldFailWithUpgradeNotAllowed.

@Test
void startTheDatabaseWithWrongVersionShouldFailWithUpgradeNotAllowed() throws Throwable {
    // given
    // create a store
    DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).build();
    GraphDatabaseAPI db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    try (Transaction tx = db.beginTx()) {
        tx.createNode();
        tx.commit();
    }
    managementService.shutdown();
    // mess up the version in the metadatastore
    try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
        ThreadPoolJobScheduler scheduler = new ThreadPoolJobScheduler();
        PageCache pageCache = createPageCache(fileSystem, scheduler, PageCacheTracer.NULL)) {
        MetaDataStore.setRecord(pageCache, databaseLayout.metadataStore(), MetaDataStore.Position.STORE_VERSION, MetaDataStore.versionStringToLong("bad"), databaseLayout.getDatabaseName(), NULL);
    }
    managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).build();
    GraphDatabaseAPI databaseService = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    try {
        assertThrows(DatabaseShutdownException.class, databaseService::beginTx);
        DatabaseStateService dbStateService = databaseService.getDependencyResolver().resolveDependency(DatabaseStateService.class);
        assertTrue(dbStateService.causeOfFailure(databaseService.databaseId()).isPresent());
        Throwable throwable = findCauseOrSuppressed(dbStateService.causeOfFailure(databaseService.databaseId()).get(), e -> e instanceof IllegalArgumentException).get();
        assertEquals("Unknown store version 'bad'", throwable.getMessage());
    } finally {
        managementService.shutdown();
    }
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) GraphDatabaseSettings(org.neo4j.configuration.GraphDatabaseSettings) LogAssertions.assertThat(org.neo4j.logging.LogAssertions.assertThat) StandalonePageCacheFactory.createPageCache(org.neo4j.io.pagecache.impl.muninn.StandalonePageCacheFactory.createPageCache) Config(org.neo4j.configuration.Config) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) DEFAULT_DATABASE_NAME(org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Inject(org.neo4j.test.extension.Inject) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) PageCacheTracer(org.neo4j.io.pagecache.tracing.PageCacheTracer) NULL(org.neo4j.io.pagecache.context.CursorContext.NULL) GraphDatabaseInternalSettings(org.neo4j.configuration.GraphDatabaseInternalSettings) DbmsInfo(org.neo4j.kernel.impl.factory.DbmsInfo) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Transaction(org.neo4j.graphdb.Transaction) Path(java.nio.file.Path) PageCache(org.neo4j.io.pagecache.PageCache) Exceptions.findCauseOrSuppressed(org.neo4j.internal.helpers.Exceptions.findCauseOrSuppressed) DatabaseManagementServiceBuilder(org.neo4j.dbms.api.DatabaseManagementServiceBuilder) IOException(java.io.IOException) Neo4jLayoutExtension(org.neo4j.test.extension.Neo4jLayoutExtension) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Test(org.junit.jupiter.api.Test) DatabaseStateService(org.neo4j.dbms.DatabaseStateService) ExternalDependencies(org.neo4j.graphdb.facade.ExternalDependencies) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) EphemeralFileSystemAbstraction(org.neo4j.io.fs.EphemeralFileSystemAbstraction) MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) CommunityEditionModule(org.neo4j.graphdb.factory.module.edition.CommunityEditionModule) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) DatabaseShutdownException(org.neo4j.graphdb.DatabaseShutdownException) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) DatabaseManagementServiceFactory(org.neo4j.graphdb.facade.DatabaseManagementServiceFactory) StoreUpgrader(org.neo4j.kernel.impl.storemigration.StoreUpgrader) GlobalModule(org.neo4j.graphdb.factory.module.GlobalModule) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) EphemeralFileSystemAbstraction(org.neo4j.io.fs.EphemeralFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) DatabaseStateService(org.neo4j.dbms.DatabaseStateService) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) StandalonePageCacheFactory.createPageCache(org.neo4j.io.pagecache.impl.muninn.StandalonePageCacheFactory.createPageCache) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.jupiter.api.Test)

Example 15 with MetaDataStore

use of org.neo4j.kernel.impl.store.MetaDataStore in project neo4j by neo4j.

the class BatchingNeoStores method instantiateStores.

private void instantiateStores() throws IOException {
    neoStores = newStoreFactory(databaseLayout, idGeneratorFactory, pageCacheTracer, immutable.empty()).openAllNeoStores(true);
    propertyKeyRepository = new BatchingPropertyKeyTokenRepository(neoStores.getPropertyKeyTokenStore());
    labelRepository = new BatchingLabelTokenRepository(neoStores.getLabelTokenStore());
    relationshipTypeRepository = new BatchingRelationshipTypeTokenRepository(neoStores.getRelationshipTypeTokenStore());
    tokenHolders = new TokenHolders(new DelegatingTokenHolder((key, internal) -> propertyKeyRepository.getOrCreateId(key, internal), TYPE_PROPERTY_KEY), new DelegatingTokenHolder((key, internal) -> labelRepository.getOrCreateId(key, internal), TYPE_LABEL), new DelegatingTokenHolder((key, internal) -> relationshipTypeRepository.getOrCreateId(key, internal), TYPE_RELATIONSHIP_TYPE));
    tokenHolders.propertyKeyTokens().setInitialTokens(neoStores.getPropertyKeyTokenStore().getTokens(CursorContext.NULL));
    temporaryNeoStores = instantiateTempStores();
    try (var cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer(BATCHING_STORE_CREATION_TAG))) {
        neoStores.start(cursorContext);
        temporaryNeoStores.start(cursorContext);
        MetaDataStore metaDataStore = neoStores.getMetaDataStore();
        metaDataStore.setLastCommittedAndClosedTransactionId(initialIds.lastCommittedTransactionId(), initialIds.lastCommittedTransactionChecksum(), BASE_TX_COMMIT_TIMESTAMP, initialIds.lastCommittedTransactionLogByteOffset(), initialIds.lastCommittedTransactionLogVersion(), cursorContext);
        metaDataStore.setCheckpointLogVersion(initialIds.checkpointLogVersion(), cursorContext);
    }
}
Also used : MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore) BatchingLabelTokenRepository(org.neo4j.internal.batchimport.store.BatchingTokenRepository.BatchingLabelTokenRepository) BatchingRelationshipTypeTokenRepository(org.neo4j.internal.batchimport.store.BatchingTokenRepository.BatchingRelationshipTypeTokenRepository) BatchingPropertyKeyTokenRepository(org.neo4j.internal.batchimport.store.BatchingTokenRepository.BatchingPropertyKeyTokenRepository) CursorContext(org.neo4j.io.pagecache.context.CursorContext) TokenHolders(org.neo4j.token.TokenHolders) DelegatingTokenHolder(org.neo4j.token.DelegatingTokenHolder)

Aggregations

MetaDataStore (org.neo4j.kernel.impl.store.MetaDataStore)15 NeoStores (org.neo4j.kernel.impl.store.NeoStores)8 Test (org.junit.jupiter.api.Test)4 IOException (java.io.IOException)3 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)3 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 TransactionFailureException (org.neo4j.internal.kernel.api.exceptions.TransactionFailureException)2 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)2 PageCache (org.neo4j.io.pagecache.PageCache)2 TransactionId (org.neo4j.kernel.impl.store.TransactionId)2 LogicalTransactionStore (org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore)2 StorageCommand (org.neo4j.storageengine.api.StorageCommand)2 Path (java.nio.file.Path)1 Optional (java.util.Optional)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)1 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)1 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)1 RequestContext (org.neo4j.com.RequestContext)1