Search in sources :

Example 46 with EphemeralFileSystemAbstraction

use of org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction in project neo4j by neo4j.

the class LabelRecoveryTest method shouldRecoverNodeWithDynamicLabelRecords.

/**
     * Reading a node command might leave a node record which referred to
     * labels in one or more dynamic records as marked as heavy even if that
     * node already had references to dynamic records, changed in a transaction,
     * but had no labels on that node changed within that same transaction.
     * Now defensively only marks as heavy if there were one or more dynamic
     * records provided when providing the record object with the label field
     * value. This would give the opportunity to load the dynamic records the
     * next time that record would be ensured heavy.
     */
@Test
public void shouldRecoverNodeWithDynamicLabelRecords() throws Exception {
    // GIVEN
    database = new TestGraphDatabaseFactory().setFileSystem(fs).newImpermanentDatabase();
    Node node;
    Label[] labels = new Label[] { label("a"), label("b"), label("c"), label("d"), label("e"), label("f"), label("g"), label("h"), label("i"), label("j"), label("k") };
    try (Transaction tx = database.beginTx()) {
        node = database.createNode(labels);
        tx.success();
    }
    // WHEN
    try (Transaction tx = database.beginTx()) {
        node.setProperty("prop", "value");
        tx.success();
    }
    EphemeralFileSystemAbstraction snapshot = fs.snapshot();
    database.shutdown();
    database = new TestGraphDatabaseFactory().setFileSystem(snapshot).newImpermanentDatabase();
    // THEN
    try (Transaction ignored = database.beginTx()) {
        node = database.getNodeById(node.getId());
        for (Label label : labels) {
            assertTrue(node.hasLabel(label));
        }
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) Node(org.neo4j.graphdb.Node) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Label(org.neo4j.graphdb.Label) Test(org.junit.Test)

Example 47 with EphemeralFileSystemAbstraction

use of org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction in project neo4j by neo4j.

the class KernelIntegrationTest method setup.

@Before
public void setup() {
    fs = new EphemeralFileSystemAbstraction();
    startDb();
}
Also used : EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) Before(org.junit.Before)

Example 48 with EphemeralFileSystemAbstraction

use of org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction 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 49 with EphemeralFileSystemAbstraction

use of org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction in project neo4j by neo4j.

the class NodeStoreTest method shouldCombineProperFiveByteLabelField.

@Test
public void shouldCombineProperFiveByteLabelField() throws Exception {
    // GIVEN
    // -- a store
    EphemeralFileSystemAbstraction fs = efs.get();
    nodeStore = newNodeStore(fs);
    // -- a record with the msb carrying a negative value
    long nodeId = 0, labels = 0x8000000001L;
    NodeRecord record = new NodeRecord(nodeId, false, NO_NEXT_RELATIONSHIP.intValue(), NO_NEXT_PROPERTY.intValue());
    record.setInUse(true);
    record.setLabelField(labels, Collections.<DynamicRecord>emptyList());
    nodeStore.updateRecord(record);
    // WHEN
    // -- reading that record back
    NodeRecord readRecord = nodeStore.getRecord(nodeId, nodeStore.newRecord(), NORMAL);
    // THEN
    // -- the label field must be the same
    assertEquals(labels, readRecord.getLabelField());
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) Test(org.junit.Test)

Example 50 with EphemeralFileSystemAbstraction

use of org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction in project neo4j by neo4j.

the class NodeStoreTest method shouldFreeSecondaryUnitIdOfShrunkRecord.

@Test
public void shouldFreeSecondaryUnitIdOfShrunkRecord() throws Exception {
    // GIVEN
    EphemeralFileSystemAbstraction fs = efs.get();
    nodeStore = newNodeStore(fs);
    NodeRecord record = new NodeRecord(5L);
    record.setRequiresSecondaryUnit(true);
    record.setSecondaryUnitId(10L);
    record.setInUse(true);
    nodeStore.updateRecord(record);
    nodeStore.setHighestPossibleIdInUse(10L);
    // WHEN
    record.setRequiresSecondaryUnit(false);
    nodeStore.updateRecord(record);
    // THEN
    IdGenerator idGenerator = idGeneratorFactory.get(IdType.NODE);
    verify(idGenerator, times(0)).freeId(5L);
    verify(idGenerator).freeId(10L);
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) IdGenerator(org.neo4j.kernel.impl.store.id.IdGenerator) Test(org.junit.Test)

Aggregations

EphemeralFileSystemAbstraction (org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction)54 Test (org.junit.Test)37 File (java.io.File)27 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)10 StoreChannel (org.neo4j.io.fs.StoreChannel)8 IOException (java.io.IOException)7 AdversarialFileSystemAbstraction (org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction)7 Before (org.junit.Before)6 CountingAdversary (org.neo4j.adversaries.CountingAdversary)6 Transaction (org.neo4j.graphdb.Transaction)6 ByteBuffer (java.nio.ByteBuffer)5 MethodGuardedAdversary (org.neo4j.adversaries.MethodGuardedAdversary)5 StateRecoveryManager (org.neo4j.causalclustering.core.state.StateRecoveryManager)5 EndOfStreamException (org.neo4j.causalclustering.messaging.EndOfStreamException)5 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Node (org.neo4j.graphdb.Node)4 SelectiveFileSystemAbstraction (org.neo4j.graphdb.mockfs.SelectiveFileSystemAbstraction)4 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)4 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)4