Search in sources :

Example 31 with Lifespan

use of org.neo4j.kernel.lifecycle.Lifespan in project neo4j by neo4j.

the class AbstractKeyValueStoreTest method shouldNotPickCorruptStoreFile.

@Test
public void shouldNotPickCorruptStoreFile() throws Exception {
    // given
    Store store = createTestStore();
    RotationStrategy rotation = store.rotationStrategy;
    // when
    File[] files = new File[10];
    {
        Pair<File, KeyValueStoreFile> file = rotation.create(EMPTY_DATA_PROVIDER, 1);
        files[0] = file.first();
        for (int txId = 2, i = 1; i < files.length; txId <<= 1, i++) {
            KeyValueStoreFile old = file.other();
            final int data = txId;
            file = rotation.next(file.first(), Headers.headersBuilder().put(TX_ID, (long) txId).headers(), data(new Entry() {

                @Override
                public void write(WritableBuffer key, WritableBuffer value) {
                    key.putByte(0, (byte) 'f');
                    key.putByte(1, (byte) 'o');
                    key.putByte(2, (byte) 'o');
                    value.putInt(0, data);
                }
            }));
            old.close();
            files[i] = file.first();
        }
        file.other().close();
    }
    // Corrupt the last files
    try (StoreChannel channel = resourceManager.fileSystem().open(files[9], "rw")) {
        // ruin the header
        channel.position(16);
        ByteBuffer value = ByteBuffer.allocate(16);
        value.put((byte) 0);
        value.flip();
        channel.writeAll(value);
    }
    try (StoreChannel channel = resourceManager.fileSystem().open(files[8], "rw")) {
        // ruin the header
        channel.position(32);
        ByteBuffer value = ByteBuffer.allocate(16);
        value.put((byte) 17);
        value.flip();
        channel.writeAll(value);
    }
    try (StoreChannel channel = resourceManager.fileSystem().open(files[7], "rw")) {
        // ruin the header
        channel.position(32 + 32 + 32 + 16);
        ByteBuffer value = ByteBuffer.allocate(16);
        value.putLong(0);
        value.putLong(0);
        value.flip();
        channel.writeAll(value);
    }
    // then
    try (Lifespan life = new Lifespan()) {
        life.add(store);
        assertEquals(64L, store.headers().get(TX_ID).longValue());
    }
}
Also used : StoreChannel(org.neo4j.io.fs.StoreChannel) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) File(java.io.File) ByteBuffer(java.nio.ByteBuffer) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) Pair(org.neo4j.helpers.collection.Pair) Test(org.junit.Test)

Example 32 with Lifespan

use of org.neo4j.kernel.lifecycle.Lifespan in project neo4j by neo4j.

the class CountsComputerTest method rebuildCounts.

private void rebuildCounts(long lastCommittedTransactionId) throws IOException {
    cleanupCountsForRebuilding();
    StoreFactory storeFactory = new StoreFactory(dir, pageCache, fs, NullLogProvider.getInstance());
    try (Lifespan life = new Lifespan();
        NeoStores neoStores = storeFactory.openAllNeoStores()) {
        NodeStore nodeStore = neoStores.getNodeStore();
        RelationshipStore relationshipStore = neoStores.getRelationshipStore();
        int highLabelId = (int) neoStores.getLabelTokenStore().getHighId();
        int highRelationshipTypeId = (int) neoStores.getRelationshipTypeTokenStore().getHighId();
        CountsComputer countsComputer = new CountsComputer(lastCommittedTransactionId, nodeStore, relationshipStore, highLabelId, highRelationshipTypeId);
        CountsTracker countsTracker = createCountsTracker();
        life.add(countsTracker.setInitializer(countsComputer));
    }
}
Also used : NodeStore(org.neo4j.kernel.impl.store.NodeStore) CountsComputer(org.neo4j.kernel.impl.store.CountsComputer) NeoStores(org.neo4j.kernel.impl.store.NeoStores) RelationshipStore(org.neo4j.kernel.impl.store.RelationshipStore) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) Lifespan(org.neo4j.kernel.lifecycle.Lifespan)

Aggregations

Lifespan (org.neo4j.kernel.lifecycle.Lifespan)32 Test (org.junit.Test)22 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)8 Transaction (org.neo4j.graphdb.Transaction)6 File (java.io.File)5 Node (org.neo4j.graphdb.Node)4 DurableStateStorage (org.neo4j.causalclustering.core.state.storage.DurableStateStorage)3 EphemeralFileSystemAbstraction (org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction)3 StoreChannel (org.neo4j.io.fs.StoreChannel)3 CountsOracle (org.neo4j.kernel.impl.store.CountsOracle)3 PhysicalLogFiles (org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles)3 ReadOnlyTransactionIdStore (org.neo4j.kernel.impl.transaction.log.ReadOnlyTransactionIdStore)3 TransactionIdStore (org.neo4j.kernel.impl.transaction.log.TransactionIdStore)3 Monitors (org.neo4j.kernel.monitoring.Monitors)3 IOException (java.io.IOException)2 ByteBuffer (java.nio.ByteBuffer)2 Future (java.util.concurrent.Future)2 StateMarshal (org.neo4j.causalclustering.core.state.storage.StateMarshal)2 MemberId (org.neo4j.causalclustering.identity.MemberId)2 PageCache (org.neo4j.io.pagecache.PageCache)2