Search in sources :

Example 1 with SimpleTriggerInfo

use of org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo in project neo4j by neo4j.

the class CountsRotationTest method checkPoint.

private void checkPoint(GraphDatabaseAPI db) throws IOException {
    TriggerInfo triggerInfo = new SimpleTriggerInfo("test");
    db.getDependencyResolver().resolveDependency(CheckPointer.class).forceCheckPoint(triggerInfo);
}
Also used : SimpleTriggerInfo(org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo) TriggerInfo(org.neo4j.kernel.impl.transaction.log.checkpoint.TriggerInfo) SimpleTriggerInfo(org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo) CheckPointer(org.neo4j.kernel.impl.transaction.log.checkpoint.CheckPointer)

Example 2 with SimpleTriggerInfo

use of org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo in project neo4j by neo4j.

the class TransactionRepresentationCommitProcessIT method commitDuringContinuousCheckpointing.

@Test(timeout = 15000)
public void commitDuringContinuousCheckpointing() throws Exception {
    final Index<Node> index;
    try (Transaction tx = db.beginTx()) {
        index = db.index().forNodes(INDEX_NAME, stringMap(IndexManager.PROVIDER, DummyIndexExtensionFactory.IDENTIFIER));
        tx.success();
    }
    final AtomicBoolean done = new AtomicBoolean();
    Workers<Runnable> workers = new Workers<>(getClass().getSimpleName());
    for (int i = 0; i < TOTAL_ACTIVE_THREADS; i++) {
        workers.start(new Runnable() {

            private final ThreadLocalRandom random = ThreadLocalRandom.current();

            @Override
            public void run() {
                while (!done.get()) {
                    try (Transaction tx = db.beginTx()) {
                        Node node = db.createNode();
                        index.add(node, "key", node.getId());
                        tx.success();
                    }
                    randomSleep();
                }
            }

            private void randomSleep() {
                try {
                    Thread.sleep(random.nextInt(50));
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
    }
    Thread.sleep(SECONDS.toMillis(2));
    done.set(true);
    workers.awaitAndThrowOnError(RuntimeException.class);
    NeoStores neoStores = getDependency(RecordStorageEngine.class).testAccessNeoStores();
    assertThat("Count store should be rotated once at least", neoStores.getCounts().txId(), greaterThan(0L));
    long lastRotationTx = getDependency(CheckPointer.class).forceCheckPoint(new SimpleTriggerInfo("test"));
    assertEquals("NeoStore last closed transaction id should be equal last count store rotation transaction id.", neoStores.getMetaDataStore().getLastClosedTransactionId(), lastRotationTx);
    assertEquals("Last closed transaction should be last rotated tx in count store", neoStores.getMetaDataStore().getLastClosedTransactionId(), neoStores.getCounts().txId());
}
Also used : Node(org.neo4j.graphdb.Node) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SimpleTriggerInfo(org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo) Transaction(org.neo4j.graphdb.Transaction) Workers(org.neo4j.unsafe.impl.batchimport.cache.idmapping.string.Workers) RecordStorageEngine(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine) NeoStores(org.neo4j.kernel.impl.store.NeoStores) CheckPointer(org.neo4j.kernel.impl.transaction.log.checkpoint.CheckPointer) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Test(org.junit.Test)

Example 3 with SimpleTriggerInfo

use of org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo in project neo4j by neo4j.

the class TestRecoveryMultipleDataSources method main.

public static void main(String[] args) throws IOException {
    if (args.length != 1) {
        exit(1);
    }
    File storeDir = new File(args[0]);
    GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabase(storeDir);
    try (Transaction tx = db.beginTx()) {
        db.createNode().createRelationshipTo(db.createNode(), MyRelTypes.TEST);
        tx.success();
    }
    ((GraphDatabaseAPI) db).getDependencyResolver().resolveDependency(CheckPointer.class).forceCheckPoint(new SimpleTriggerInfo("test"));
    try (Transaction tx = db.beginTx()) {
        db.index().forNodes("index").add(db.createNode(), storeDir.getAbsolutePath(), db.createNode());
        tx.success();
    }
    exit(0);
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) SimpleTriggerInfo(org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo) Transaction(org.neo4j.graphdb.Transaction) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) CheckPointer(org.neo4j.kernel.impl.transaction.log.checkpoint.CheckPointer) File(java.io.File)

Example 4 with SimpleTriggerInfo

use of org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo in project neo4j by neo4j.

the class GetStoreRequestHandler method channelRead0.

@Override
protected void channelRead0(ChannelHandlerContext ctx, GetStoreRequest msg) throws Exception {
    if (!msg.expectedStoreId().equalToKernelStoreId(dataSource.get().getStoreId())) {
        endStoreCopy(SUCCESS, ctx, -1);
    } else {
        CheckPointer checkPointer = checkPointerSupplier.get();
        long lastCheckPointedTx;
        try (Resource lock = mutex.storeCopy(() -> checkPointer.tryCheckPoint(new SimpleTriggerInfo("Store copy")));
            ResourceIterator<StoreFileMetadata> files = dataSource.get().listStoreFiles(false)) {
            lastCheckPointedTx = checkPointer.lastCheckPointedTransactionId();
            while (files.hasNext()) {
                StoreFileMetadata fileMetadata = files.next();
                File file = fileMetadata.file();
                log.debug("Sending file " + file);
                ctx.writeAndFlush(ResponseMessageType.FILE);
                ctx.writeAndFlush(new FileHeader(relativePath(dataSource.get().getStoreDir(), file), fileMetadata.recordSize()));
                Optional<PagedFile> existingMapping = pageCache.getExistingMapping(file);
                if (existingMapping.isPresent()) {
                    try (PagedFile pagedFile = existingMapping.get()) {
                        ctx.writeAndFlush(new FileSender(pagedFile.openReadableByteChannel()));
                    }
                } else {
                    ctx.writeAndFlush(new FileSender(fs.open(file, "r")));
                }
            }
        }
        endStoreCopy(SUCCESS, ctx, lastCheckPointedTx);
    }
    protocol.expect(State.MESSAGE_TYPE);
}
Also used : SimpleTriggerInfo(org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo) PagedFile(org.neo4j.io.pagecache.PagedFile) CheckPointer(org.neo4j.kernel.impl.transaction.log.checkpoint.CheckPointer) Resource(org.neo4j.graphdb.Resource) StoreFileMetadata(org.neo4j.storageengine.api.StoreFileMetadata) PagedFile(org.neo4j.io.pagecache.PagedFile) File(java.io.File)

Example 5 with SimpleTriggerInfo

use of org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo in project neo4j by neo4j.

the class IndexCreationTest method verifyThatIndexCreationTransactionIsTheFirstOne.

private void verifyThatIndexCreationTransactionIsTheFirstOne() throws Exception {
    PhysicalLogFile pLogFile = db.getDependencyResolver().resolveDependency(PhysicalLogFile.class);
    long version = db.getDependencyResolver().resolveDependency(LogVersionRepository.class).getCurrentLogVersion();
    db.getDependencyResolver().resolveDependency(LogRotation.class).rotateLogFile();
    db.getDependencyResolver().resolveDependency(CheckPointer.class).forceCheckPoint(new SimpleTriggerInfo("test"));
    ReadableLogChannel logChannel = pLogFile.getReader(LogPosition.start(version));
    final AtomicBoolean success = new AtomicBoolean(false);
    try (IOCursor<LogEntry> cursor = new LogEntryCursor(new VersionAwareLogEntryReader<>(), logChannel)) {
        List<StorageCommand> commandsInFirstEntry = new ArrayList<>();
        boolean startFound = false;
        while (cursor.next()) {
            LogEntry entry = cursor.get();
            if (entry instanceof LogEntryStart) {
                if (startFound) {
                    throw new IllegalArgumentException("More than one start entry");
                }
                startFound = true;
            }
            if (startFound && entry instanceof LogEntryCommand) {
                commandsInFirstEntry.add(entry.<LogEntryCommand>as().getXaCommand());
            }
            if (entry instanceof LogEntryCommit) {
                // The first COMMIT
                assertTrue(startFound);
                assertFalse("Index creation transaction wasn't the first one", commandsInFirstEntry.isEmpty());
                List<StorageCommand> createCommands = Iterators.asList(new FilteringIterator<>(commandsInFirstEntry.iterator(), item -> item instanceof IndexDefineCommand));
                assertEquals(1, createCommands.size());
                success.set(true);
                break;
            }
        }
    }
    assertTrue("Didn't find any commit record in log " + version, success.get());
}
Also used : LogEntryStart(org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart) LogEntryCursor(org.neo4j.kernel.impl.transaction.log.LogEntryCursor) CheckPointer(org.neo4j.kernel.impl.transaction.log.checkpoint.CheckPointer) Iterators(org.neo4j.helpers.collection.Iterators) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IOCursor(org.neo4j.cursor.IOCursor) Node(org.neo4j.graphdb.Node) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) ArrayList(java.util.ArrayList) StorageCommand(org.neo4j.storageengine.api.StorageCommand) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) LogRotation(org.neo4j.kernel.impl.transaction.log.rotation.LogRotation) After(org.junit.After) Transaction(org.neo4j.graphdb.Transaction) ReadableLogChannel(org.neo4j.kernel.impl.transaction.log.ReadableLogChannel) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) LogEntryCommit(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit) IndexDefineCommand(org.neo4j.kernel.impl.index.IndexDefineCommand) LogVersionRepository(org.neo4j.kernel.impl.transaction.log.LogVersionRepository) TestDirectory(org.neo4j.test.rule.TestDirectory) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) LogEntryStart(org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) SimpleTriggerInfo(org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Rule(org.junit.Rule) LogEntryCommand(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand) Executors.newCachedThreadPool(java.util.concurrent.Executors.newCachedThreadPool) Assert.assertFalse(org.junit.Assert.assertFalse) FilteringIterator(org.neo4j.helpers.collection.FilteringIterator) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry) Assert.assertEquals(org.junit.Assert.assertEquals) Index(org.neo4j.graphdb.index.Index) ReadableLogChannel(org.neo4j.kernel.impl.transaction.log.ReadableLogChannel) LogEntryCommand(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand) IndexDefineCommand(org.neo4j.kernel.impl.index.IndexDefineCommand) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ArrayList(java.util.ArrayList) LogVersionRepository(org.neo4j.kernel.impl.transaction.log.LogVersionRepository) LogEntryCursor(org.neo4j.kernel.impl.transaction.log.LogEntryCursor) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SimpleTriggerInfo(org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo) LogEntryCommit(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit) CheckPointer(org.neo4j.kernel.impl.transaction.log.checkpoint.CheckPointer) LogRotation(org.neo4j.kernel.impl.transaction.log.rotation.LogRotation) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry)

Aggregations

SimpleTriggerInfo (org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo)15 CheckPointer (org.neo4j.kernel.impl.transaction.log.checkpoint.CheckPointer)14 LogRotation (org.neo4j.kernel.impl.transaction.log.rotation.LogRotation)7 File (java.io.File)4 Test (org.junit.Test)4 Transaction (org.neo4j.graphdb.Transaction)4 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)3 IOException (java.io.IOException)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Node (org.neo4j.graphdb.Node)2 Resource (org.neo4j.graphdb.Resource)2 PagedFile (org.neo4j.io.pagecache.PagedFile)2 TriggerInfo (org.neo4j.kernel.impl.transaction.log.checkpoint.TriggerInfo)2 StoreFileMetadata (org.neo4j.storageengine.api.StoreFileMetadata)2 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)2 UncheckedIOException (java.io.UncheckedIOException)1 ByteBuffer (java.nio.ByteBuffer)1 ReadableByteChannel (java.nio.channels.ReadableByteChannel)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1