Search in sources :

Example 6 with IdType

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

the class EnterpriseEditionSettingsTest method idTypesToReuseAllowedValues.

@Test
public void idTypesToReuseAllowedValues() {
    for (IdType type : IdType.values()) {
        if (type == IdType.NODE || type == IdType.RELATIONSHIP) {
            assertIdTypesToReuseAllows(type);
        } else {
            assertIdTypesToReuseDisallows(type);
        }
    }
    assertIdTypesToReuseAllows(IdType.NODE, IdType.RELATIONSHIP);
    assertIdTypesToReuseAllows(IdType.RELATIONSHIP, IdType.NODE);
    assertIdTypesToReuseDisallows(IdType.NODE, IdType.RELATIONSHIP, IdType.RELATIONSHIP_GROUP);
    assertIdTypesToReuseDisallows(IdType.SCHEMA, IdType.NEOSTORE_BLOCK);
}
Also used : IdType(org.neo4j.kernel.impl.store.id.IdType) Test(org.junit.Test)

Example 7 with IdType

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

the class TestCrashWithRebuildSlow method crashAndRebuildSlowWithDynamicStringDeletions.

@Test
public void crashAndRebuildSlowWithDynamicStringDeletions() throws Exception {
    File storeDir = new File("dir").getAbsoluteFile();
    final GraphDatabaseAPI db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().setFileSystem(fs.get()).newImpermanentDatabase(storeDir);
    List<Long> deletedNodeIds = produceNonCleanDefraggedStringStore(db);
    Map<IdType, Long> highIdsBeforeCrash = getHighIds(db);
    long checksumBefore = fs.get().checksum();
    long checksumBefore2 = fs.get().checksum();
    assertThat(checksumBefore, Matchers.equalTo(checksumBefore2));
    EphemeralFileSystemAbstraction snapshot = fs.snapshot(() -> db.shutdown());
    long snapshotChecksum = snapshot.checksum();
    if (snapshotChecksum != checksumBefore) {
        try (OutputStream out = new FileOutputStream(testDir.file("snapshot.zip"))) {
            snapshot.dumpZip(out);
        }
        try (OutputStream out = new FileOutputStream(testDir.file("fs.zip"))) {
            fs.get().dumpZip(out);
        }
    }
    assertThat(snapshotChecksum, equalTo(checksumBefore));
    // Recover with unsupported.dbms.id_generator_fast_rebuild_enabled=false
    assertNumberOfFreeIdsEquals(storeDir, snapshot, 0);
    GraphDatabaseAPI newDb = (GraphDatabaseAPI) new TestGraphDatabaseFactory().setFileSystem(snapshot).newImpermanentDatabaseBuilder(storeDir).setConfig(GraphDatabaseSettings.rebuild_idgenerators_fast, FALSE).newGraphDatabase();
    Map<IdType, Long> highIdsAfterCrash = getHighIds(newDb);
    assertEquals(highIdsBeforeCrash, highIdsAfterCrash);
    try (Transaction tx = newDb.beginTx()) {
        // Verify that the data we didn't delete is still around
        int nameCount = 0;
        int relCount = 0;
        for (Node node : newDb.getAllNodes()) {
            nameCount++;
            assertThat(node, inTx(newDb, hasProperty("name"), true));
            relCount += Iterables.count(node.getRelationships(Direction.OUTGOING));
        }
        assertEquals(16, nameCount);
        assertEquals(12, relCount);
        // Verify that the ids of the nodes we deleted are reused
        List<Long> newIds = new ArrayList<>();
        newIds.add(newDb.createNode().getId());
        newIds.add(newDb.createNode().getId());
        newIds.add(newDb.createNode().getId());
        newIds.add(newDb.createNode().getId());
        assertThat(newIds, is(deletedNodeIds));
        tx.success();
    } finally {
        newDb.shutdown();
        snapshot.close();
    }
}
Also used : EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) Node(org.neo4j.graphdb.Node) ArrayList(java.util.ArrayList) IdType(org.neo4j.kernel.impl.store.id.IdType) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) FileOutputStream(java.io.FileOutputStream) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) File(java.io.File) Test(org.junit.Test)

Example 8 with IdType

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

the class TestCrashWithRebuildSlow method getHighIds.

private static Map<IdType, Long> getHighIds(GraphDatabaseAPI db) {
    final Map<IdType, Long> highIds = new HashMap<>();
    NeoStores neoStores = db.getDependencyResolver().resolveDependency(RecordStorageEngine.class).testAccessNeoStores();
    Visitor<CommonAbstractStore, RuntimeException> visitor = new Visitor<CommonAbstractStore, RuntimeException>() {

        @Override
        public boolean visit(CommonAbstractStore store) throws RuntimeException {
            highIds.put(store.getIdType(), store.getHighId());
            return true;
        }
    };
    neoStores.visitStore(visitor);
    return highIds;
}
Also used : Visitor(org.neo4j.helpers.collection.Visitor) HashMap(java.util.HashMap) RecordStorageEngine(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine) NeoStores(org.neo4j.kernel.impl.store.NeoStores) CommonAbstractStore(org.neo4j.kernel.impl.store.CommonAbstractStore) IdType(org.neo4j.kernel.impl.store.id.IdType)

Aggregations

IdType (org.neo4j.kernel.impl.store.id.IdType)8 Test (org.junit.Test)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Config (org.neo4j.kernel.configuration.Config)2 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 String.format (java.lang.String.format)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 Stream (java.util.stream.Stream)1 Nonnull (javax.annotation.Nonnull)1 Matchers.hasItems (org.hamcrest.Matchers.hasItems)1