Search in sources :

Example 51 with DatabaseManagementService

use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.

the class PointPropertiesRecordFormatIT method createPointArrayPropertyOnLatestDatabase.

@Test
void createPointArrayPropertyOnLatestDatabase() {
    Path storeDir = testDirectory.homePath();
    Label pointNode = Label.label("PointNode");
    String propertyKey = "a";
    PointValue pointValue = pointValue(Cartesian, 1.0, 2.0);
    DatabaseManagementService managementService = startDatabaseService(storeDir);
    GraphDatabaseService database = getDefaultDatabase(managementService);
    try (Transaction transaction = database.beginTx()) {
        Node node = transaction.createNode(pointNode);
        node.setProperty(propertyKey, new PointValue[] { pointValue, pointValue });
        transaction.commit();
    }
    managementService.shutdown();
    managementService = startDatabaseService(storeDir);
    GraphDatabaseService restartedDatabase = getDefaultDatabase(managementService);
    try (Transaction tx = restartedDatabase.beginTx()) {
        try (ResourceIterator<Node> nodes = tx.findNodes(pointNode)) {
            Node node = nodes.next();
            PointValue[] points = (PointValue[]) node.getProperty(propertyKey);
            assertThat(points).hasSize(2);
        }
    }
    managementService.shutdown();
}
Also used : Path(java.nio.file.Path) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) PointValue(org.neo4j.values.storable.PointValue) Node(org.neo4j.graphdb.Node) Label(org.neo4j.graphdb.Label) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 52 with DatabaseManagementService

use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.

the class PointPropertiesRecordFormatIT method createPointPropertyOnLatestDatabase.

@Test
void createPointPropertyOnLatestDatabase() {
    Path storeDir = testDirectory.homePath();
    Label pointNode = Label.label("PointNode");
    String propertyKey = "a";
    PointValue pointValue = pointValue(Cartesian, 1.0, 2.0);
    DatabaseManagementService managementService = startDatabaseService(storeDir);
    GraphDatabaseService database = getDefaultDatabase(managementService);
    try (Transaction transaction = database.beginTx()) {
        Node node = transaction.createNode(pointNode);
        node.setProperty(propertyKey, pointValue);
        transaction.commit();
    }
    managementService.shutdown();
    managementService = startDatabaseService(storeDir);
    GraphDatabaseService restartedDatabase = getDefaultDatabase(managementService);
    try (Transaction transaction = restartedDatabase.beginTx()) {
        assertNotNull(transaction.findNode(pointNode, propertyKey, pointValue));
    }
    managementService.shutdown();
}
Also used : Path(java.nio.file.Path) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) PointValue(org.neo4j.values.storable.PointValue) Node(org.neo4j.graphdb.Node) Label(org.neo4j.graphdb.Label) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 53 with DatabaseManagementService

use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.

the class RecoveryCorruptedTransactionLogIT method startStopDatabaseAndGetTxOffset.

private long startStopDatabaseAndGetTxOffset() {
    DatabaseManagementService managementService = databaseFactory.build();
    final GraphDatabaseAPI database = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    storageEngineFactory = database.getDependencyResolver().resolveDependency(StorageEngineFactory.class);
    long offset = getLastClosedTransactionOffset(database);
    managementService.shutdown();
    return offset;
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) StorageEngineFactory(org.neo4j.storageengine.api.StorageEngineFactory) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService)

Example 54 with DatabaseManagementService

use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.

the class RecoveryCorruptedTransactionLogIT method restoreCheckpointLogVersionFromFileVersion.

@Test
void restoreCheckpointLogVersionFromFileVersion() throws IOException {
    DatabaseManagementService managementService = databaseFactory.build();
    GraphDatabaseAPI database = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    logFiles = buildDefaultLogFiles(getStoreId(database));
    generateTransaction(database);
    managementService.shutdown();
    int rotations = 10;
    try (Lifespan lifespan = new Lifespan(logFiles)) {
        CheckpointFile checkpointFile = logFiles.getCheckpointFile();
        DetachedCheckpointAppender checkpointAppender = (DetachedCheckpointAppender) checkpointFile.getCheckpointAppender();
        for (int i = 0; i < rotations; i++) {
            checkpointAppender.checkPoint(LogCheckPointEvent.NULL, new LogPosition(0, HEADER_OFFSET), Instant.now(), "test" + i);
            checkpointAppender.rotate();
        }
    }
    for (int i = rotations - 1; i > 0; i--) {
        var restartedDbms = databaseFactory.build();
        try {
            StorageEngine storageEngine = ((GraphDatabaseAPI) restartedDbms.database(DEFAULT_DATABASE_NAME)).getDependencyResolver().resolveDependency(StorageEngine.class);
            assertEquals(i, storageEngine.metadataProvider().getCheckpointLogVersion());
        } finally {
            restartedDbms.shutdown();
        }
        // we remove 3 checkpoints: 1 from shutdown and 1 from recovery and one that we created in a loop before
        removeLastCheckpointRecordFromLastLogFile();
        removeLastCheckpointRecordFromLastLogFile();
        removeLastCheckpointRecordFromLastLogFile();
    }
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) DetachedCheckpointAppender(org.neo4j.kernel.impl.transaction.log.checkpoint.DetachedCheckpointAppender) StorageEngine(org.neo4j.storageengine.api.StorageEngine) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) CheckpointFile(org.neo4j.kernel.impl.transaction.log.files.checkpoint.CheckpointFile) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 55 with DatabaseManagementService

use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.

the class RecoveryCorruptedTransactionLogIT method failToStartWithTransactionLogsWithDataAfterLastEntry.

@Test
void failToStartWithTransactionLogsWithDataAfterLastEntry() throws IOException {
    DatabaseManagementService managementService = databaseFactory.build();
    GraphDatabaseAPI database = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    logFiles = buildDefaultLogFiles(getStoreId(database));
    generateTransaction(database);
    managementService.shutdown();
    writeRandomBytesAfterLastCommandInLastLogFile(() -> ByteBuffer.wrap(new byte[] { 1, 2, 3, 4, 5 }));
    startStopDatabase();
    assertThat(logProvider).assertExceptionForLogMessage("Fail to read transaction log version 0.").hasMessageContaining("Transaction log files with version 0 has some data available after last readable " + "log entry. Last readable position " + (996 + txOffsetAfterStart));
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)155 Test (org.junit.jupiter.api.Test)100 TestDatabaseManagementServiceBuilder (org.neo4j.test.TestDatabaseManagementServiceBuilder)79 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)61 Transaction (org.neo4j.graphdb.Transaction)60 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)56 Path (java.nio.file.Path)37 Node (org.neo4j.graphdb.Node)29 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)26 Label (org.neo4j.graphdb.Label)16 MethodSource (org.junit.jupiter.params.provider.MethodSource)10 EphemeralFileSystemAbstraction (org.neo4j.io.fs.EphemeralFileSystemAbstraction)9 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)9 DatabaseStateService (org.neo4j.dbms.DatabaseStateService)8 Config (org.neo4j.configuration.Config)7 DatabaseManagementServiceBuilder (org.neo4j.dbms.api.DatabaseManagementServiceBuilder)7 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)7 GBPTreeCountsStore (org.neo4j.internal.counts.GBPTreeCountsStore)6 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)6 Lifespan (org.neo4j.kernel.lifecycle.Lifespan)6