Search in sources :

Example 21 with ReadableClosablePositionAwareChannel

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

the class NeoStoreDataSource method start.

@Override
public void start() throws IOException {
    dependencies = new Dependencies();
    life = new LifeSupport();
    schemaIndexProvider = dependencyResolver.resolveDependency(SchemaIndexProvider.class, HighestSelectionStrategy.getInstance());
    labelScanStoreProvider = dependencyResolver.resolveDependency(LabelScanStoreProvider.class, new NamedLabelScanStoreSelectionStrategy(config));
    dependencyResolver.resolveDependency(LabelScanStoreProvider.class, new DeleteStoresFromOtherLabelScanStoreProviders(labelScanStoreProvider));
    IndexConfigStore indexConfigStore = new IndexConfigStore(storeDir, fs);
    dependencies.satisfyDependency(lockService);
    dependencies.satisfyDependency(indexConfigStore);
    life.add(indexConfigStore);
    // Monitor listeners
    LoggingLogFileMonitor loggingLogMonitor = new LoggingLogFileMonitor(msgLog);
    monitors.addMonitorListener(loggingLogMonitor);
    life.add(new Delegate(Lifecycles.multiple(indexProviders.values())));
    // Upgrade the store before we begin
    RecordFormats formats = selectStoreFormats(config, storeDir, fs, pageCache, logService);
    upgradeStore(formats);
    // Build all modules and their services
    StorageEngine storageEngine = null;
    try {
        UpdateableSchemaState updateableSchemaState = new KernelSchemaStateStore(logProvider);
        SynchronizedArrayIdOrderingQueue legacyIndexTransactionOrdering = new SynchronizedArrayIdOrderingQueue(20);
        storageEngine = buildStorageEngine(propertyKeyTokenHolder, labelTokens, relationshipTypeTokens, legacyIndexProviderLookup, indexConfigStore, updateableSchemaState::clear, legacyIndexTransactionOrdering);
        LogEntryReader<ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader<>(storageEngine.commandReaderFactory());
        TransactionIdStore transactionIdStore = dependencies.resolveDependency(TransactionIdStore.class);
        LogVersionRepository logVersionRepository = dependencies.resolveDependency(LogVersionRepository.class);
        NeoStoreTransactionLogModule transactionLogModule = buildTransactionLogs(storeDir, config, logProvider, scheduler, fs, storageEngine, logEntryReader, legacyIndexTransactionOrdering, transactionIdStore, logVersionRepository);
        transactionLogModule.satisfyDependencies(dependencies);
        buildRecovery(fs, transactionIdStore, logVersionRepository, monitors.newMonitor(Recovery.Monitor.class), monitors.newMonitor(PositionToRecoverFrom.Monitor.class), transactionLogModule.logFiles(), startupStatistics, storageEngine, logEntryReader, transactionLogModule.logicalTransactionStore());
        // At the time of writing this comes from the storage engine (IndexStoreView)
        PropertyAccessor propertyAccessor = dependencies.resolveDependency(PropertyAccessor.class);
        final NeoStoreKernelModule kernelModule = buildKernel(transactionLogModule.transactionAppender(), dependencies.resolveDependency(IndexingService.class), storageEngine.storeReadLayer(), updateableSchemaState, dependencies.resolveDependency(LabelScanStore.class), storageEngine, indexConfigStore, transactionIdStore, availabilityGuard, clock, propertyAccessor);
        kernelModule.satisfyDependencies(dependencies);
        // Do these assignments last so that we can ensure no cyclical dependencies exist
        this.storageEngine = storageEngine;
        this.transactionLogModule = transactionLogModule;
        this.kernelModule = kernelModule;
        dependencies.satisfyDependency(this);
        dependencies.satisfyDependency(updateableSchemaState);
        dependencies.satisfyDependency(storageEngine.storeReadLayer());
        dependencies.satisfyDependency(logEntryReader);
        dependencies.satisfyDependency(storageEngine);
    } catch (Throwable e) {
        // Something unexpected happened during startup
        msgLog.warn("Exception occurred while setting up store modules. Attempting to close things down.", e);
        try {
            // Close the neostore, so that locks are released properly
            if (storageEngine != null) {
                storageEngine.forceClose();
            }
        } catch (Exception closeException) {
            msgLog.error("Couldn't close neostore after startup failure", closeException);
        }
        throw Exceptions.launderedException(e);
    }
    // NOTE: please make sure this is performed after having added everything to the life, in fact we would like
    // to perform the checkpointing as first step when the life is shutdown.
    life.add(lifecycleToTriggerCheckPointOnShutdown());
    try {
        life.start();
    } catch (Throwable e) {
        // Something unexpected happened during startup
        msgLog.warn("Exception occurred while starting the datasource. Attempting to close things down.", e);
        try {
            life.shutdown();
            // Close the neostore, so that locks are released properly
            storageEngine.forceClose();
        } catch (Exception closeException) {
            msgLog.error("Couldn't close neostore after startup failure", closeException);
        }
        throw Exceptions.launderedException(e);
    }
    /*
         * At this point recovery has completed and the datasource is ready for use. Whatever panic might have
         * happened before has been healed. So we can safely set the kernel health to ok.
         * This right now has any real effect only in the case of internal restarts (for example, after a store copy
         * in the case of HA). Standalone instances will have to be restarted by the user, as is proper for all
         * kernel panics.
         */
    databaseHealth.healed();
}
Also used : LabelScanStore(org.neo4j.kernel.api.labelscan.LabelScanStore) RecordStorageEngine(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine) StorageEngine(org.neo4j.storageengine.api.StorageEngine) LogVersionRepository(org.neo4j.kernel.impl.transaction.log.LogVersionRepository) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel) TransactionMonitor(org.neo4j.kernel.impl.transaction.TransactionMonitor) LoggingLogFileMonitor(org.neo4j.kernel.impl.transaction.log.LoggingLogFileMonitor) VisibleMigrationProgressMonitor(org.neo4j.kernel.impl.storemigration.monitoring.VisibleMigrationProgressMonitor) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) KernelSchemaStateStore(org.neo4j.kernel.impl.api.KernelSchemaStateStore) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) Dependencies(org.neo4j.kernel.impl.util.Dependencies) DeleteStoresFromOtherLabelScanStoreProviders(org.neo4j.kernel.extension.dependency.DeleteStoresFromOtherLabelScanStoreProviders) NamedLabelScanStoreSelectionStrategy(org.neo4j.kernel.extension.dependency.NamedLabelScanStoreSelectionStrategy) SchemaIndexProvider(org.neo4j.kernel.api.index.SchemaIndexProvider) LabelScanStoreProvider(org.neo4j.kernel.impl.api.scan.LabelScanStoreProvider) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) PropertyAccessor(org.neo4j.kernel.api.index.PropertyAccessor) LoggingLogFileMonitor(org.neo4j.kernel.impl.transaction.log.LoggingLogFileMonitor) IndexConfigStore(org.neo4j.kernel.impl.index.IndexConfigStore) IOException(java.io.IOException) KernelException(org.neo4j.kernel.api.exceptions.KernelException) UpdateableSchemaState(org.neo4j.kernel.impl.api.UpdateableSchemaState) RecordFormats(org.neo4j.kernel.impl.store.format.RecordFormats) SynchronizedArrayIdOrderingQueue(org.neo4j.kernel.impl.util.SynchronizedArrayIdOrderingQueue)

Example 22 with ReadableClosablePositionAwareChannel

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

the class Protocol method deserializeResponse.

public <PAYLOAD> Response<PAYLOAD> deserializeResponse(BlockingReadHandler<ChannelBuffer> reader, ByteBuffer input, long timeout, Deserializer<PAYLOAD> payloadDeserializer, ResourceReleaser channelReleaser, final LogEntryReader<ReadableClosablePositionAwareChannel> entryReader) throws IOException {
    final DechunkingChannelBuffer dechunkingBuffer = new DechunkingChannelBuffer(reader, timeout, internalProtocolVersion, applicationProtocolVersion);
    PAYLOAD response = payloadDeserializer.read(dechunkingBuffer, input);
    StoreId storeId = readStoreId(dechunkingBuffer, input);
    // Response type is what previously was a byte saying how many data sources there were in the
    // coming transaction stream response. For backwards compatibility we keep it as a byte and we introduce
    // the transaction obligation response type as -1
    byte responseType = dechunkingBuffer.readByte();
    if (responseType == TransactionObligationResponse.RESPONSE_TYPE) {
        // It is a transaction obligation response
        long obligationTxId = dechunkingBuffer.readLong();
        return new TransactionObligationResponse<>(response, storeId, obligationTxId, channelReleaser);
    }
    // It's a transaction stream in this response
    TransactionStream transactions = visitor -> {
        NetworkReadableClosableChannel channel = new NetworkReadableClosableChannel(dechunkingBuffer);
        try (PhysicalTransactionCursor<ReadableClosablePositionAwareChannel> cursor = new PhysicalTransactionCursor<>(channel, entryReader)) {
            while (cursor.next() && !visitor.visit(cursor.get())) {
            }
        }
    };
    return new TransactionStreamResponse<>(response, storeId, transactions, channelReleaser);
}
Also used : StoreId(org.neo4j.kernel.impl.store.StoreId) RecordFormat(org.neo4j.kernel.impl.store.format.RecordFormat) LengthFieldBasedFrameDecoder(org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder) NeoStoreDataSource(org.neo4j.kernel.NeoStoreDataSource) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) LogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader) BlockingReadHandler(org.jboss.netty.handler.queue.BlockingReadHandler) StoreWriter(org.neo4j.com.storecopy.StoreWriter) IOException(java.io.IOException) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel) Channel(org.jboss.netty.channel.Channel) ByteBuffer(java.nio.ByteBuffer) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) List(java.util.List) LogEntryWriter(org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter) LogEntryCommand(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand) LinkedList(java.util.LinkedList) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) PhysicalTransactionCursor(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionCursor) LengthFieldPrepender(org.jboss.netty.handler.codec.frame.LengthFieldPrepender) PhysicalTransactionCursor(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionCursor) StoreId(org.neo4j.kernel.impl.store.StoreId)

Example 23 with ReadableClosablePositionAwareChannel

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

the class VersionAwareLogEntryReaderTest method shouldParseStreamOfZerosAsEmptyLogEntries.

@Test
public void shouldParseStreamOfZerosAsEmptyLogEntries() throws Exception {
    // GIVEN
    LogEntryReader<ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader<>();
    InMemoryClosableChannel channel = new InMemoryClosableChannel();
    int count = 100;
    channel.put(new byte[count], count);
    // WHEN/THEN
    for (int i = 0; i < count; i++) {
        LogEntry entry = reader.readLogEntry(channel);
        assertNull(entry);
        assertEquals(i + 1, channel.readerPosition());
    }
}
Also used : InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel) Test(org.junit.Test)

Example 24 with ReadableClosablePositionAwareChannel

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

the class MigrationTestUtils method removeCheckPointFromTxLog.

public static void removeCheckPointFromTxLog(FileSystemAbstraction fileSystem, File workingDirectory) throws IOException {
    PhysicalLogFiles logFiles = new PhysicalLogFiles(workingDirectory, fileSystem);
    LogEntryReader<ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader<>();
    LatestCheckPointFinder finder = new LatestCheckPointFinder(logFiles, fileSystem, logEntryReader);
    LatestCheckPointFinder.LatestCheckPoint latestCheckPoint = finder.find(logFiles.getHighestLogVersion());
    if (latestCheckPoint.commitsAfterCheckPoint) {
        // done already
        return;
    }
    // let's assume there is at least a checkpoint
    assertNotNull(latestCheckPoint.checkPoint);
    LogPosition logPosition = latestCheckPoint.checkPoint.getLogPosition();
    File logFile = logFiles.getLogFileForVersion(logPosition.getLogVersion());
    fileSystem.truncate(logFile, logPosition.getByteOffset());
}
Also used : LatestCheckPointFinder(org.neo4j.kernel.recovery.LatestCheckPointFinder) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) File(java.io.File) PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Aggregations

ReadableClosablePositionAwareChannel (org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel)24 VersionAwareLogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)19 IOException (java.io.IOException)9 PhysicalLogFiles (org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles)8 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)8 LatestCheckPointFinder (org.neo4j.kernel.recovery.LatestCheckPointFinder)8 File (java.io.File)7 Test (org.junit.Test)7 StorageEngine (org.neo4j.storageengine.api.StorageEngine)5 CommittedTransactionRepresentation (org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation)4 LinkedList (java.util.LinkedList)3 LogHeaderCache (org.neo4j.kernel.impl.transaction.log.LogHeaderCache)3 LogicalTransactionStore (org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore)3 PhysicalLogFile (org.neo4j.kernel.impl.transaction.log.PhysicalLogFile)3 PhysicalLogicalTransactionStore (org.neo4j.kernel.impl.transaction.log.PhysicalLogicalTransactionStore)3 TransactionMetadataCache (org.neo4j.kernel.impl.transaction.log.TransactionMetadataCache)3 LogHeader (org.neo4j.kernel.impl.transaction.log.entry.LogHeader)3 DefaultRecoverySPI (org.neo4j.kernel.recovery.DefaultRecoverySPI)3 Recovery (org.neo4j.kernel.recovery.Recovery)3 ByteBuffer (java.nio.ByteBuffer)2