Search in sources :

Example 11 with ReadableClosablePositionAwareChannel

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

the class InputNodeReader method readNextOrNull.

@Override
protected InputNode readNextOrNull(Object properties, ProcessorState state) throws IOException {
    ReadableClosablePositionAwareChannel channel = state.batchChannel;
    // group
    Group group = readGroup(0, state);
    // id
    Object id = readValue(channel);
    // labels (diff from previous node)
    byte labelsMode = channel.get();
    Object labels;
    if (labelsMode == HAS_LABEL_FIELD) {
        labels = channel.getLong();
    } else if (labelsMode == END_OF_LABEL_CHANGES) {
        // Same as for previous node
        labels = state.previousLabels;
    } else {
        String[] newLabels = state.previousLabels.clone();
        int cursor = newLabels.length;
        while (labelsMode != END_OF_LABEL_CHANGES) {
            switch(labelsMode) {
                case LABEL_REMOVAL:
                    remove((String) readToken(LABEL_TOKEN, channel), newLabels, cursor--);
                    break;
                case LABEL_ADDITION:
                    (newLabels = ensureRoomForOneMore(newLabels, cursor))[cursor++] = (String) readToken(LABEL_TOKEN, channel);
                    break;
                default:
                    throw new IllegalArgumentException("Unrecognized label mode " + labelsMode);
            }
            labelsMode = channel.get();
        }
        labels = state.previousLabels = cursor == newLabels.length ? newLabels : Arrays.copyOf(newLabels, cursor);
    }
    return new InputNode(sourceDescription(), lineNumber(), position(), group, id, properties.getClass().isArray() ? (Object[]) properties : NO_PROPERTIES, properties.getClass().isArray() ? null : (Long) properties, labels.getClass().isArray() ? (String[]) labels : NO_LABELS, labels.getClass().isArray() ? null : (Long) labels);
}
Also used : ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel)

Example 12 with ReadableClosablePositionAwareChannel

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

the class InputRelationshipReader method readNextOrNull.

@Override
protected InputRelationship readNextOrNull(Object properties, ProcessorState state) throws IOException {
    ReadableClosablePositionAwareChannel channel = state.batchChannel;
    // groups
    Group startNodeGroup = readGroup(0, state);
    Group endNodeGroup = readGroup(1, state);
    // ids
    Object startNodeId = readValue(channel);
    Object endNodeId = readValue(channel);
    // type
    byte typeMode = channel.get();
    Object type;
    switch(typeMode) {
        case SAME_TYPE:
            type = state.previousType;
            break;
        case NEW_TYPE:
            type = state.previousType = (String) readToken(RELATIONSHIP_TYPE_TOKEN, channel);
            break;
        case HAS_TYPE_ID:
            type = channel.getInt();
            break;
        default:
            throw new IllegalArgumentException("Unrecognized type mode " + typeMode);
    }
    return new InputRelationship(sourceDescription(), lineNumber(), position(), properties.getClass().isArray() ? (Object[]) properties : NO_PROPERTIES, properties.getClass().isArray() ? null : (Long) properties, startNodeGroup, startNodeId, endNodeGroup, endNodeId, type instanceof String ? (String) type : null, type instanceof String ? null : (Integer) type);
}
Also used : ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel)

Example 13 with ReadableClosablePositionAwareChannel

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

the class ProtocolTest method shouldSerializeAndDeserializeTransactionRepresentation.

@Test
public void shouldSerializeAndDeserializeTransactionRepresentation() throws Exception {
    // GIVEN
    PhysicalTransactionRepresentation transaction = new PhysicalTransactionRepresentation(justOneNode());
    byte[] additionalHeader = "extra".getBytes();
    int masterId = 1, authorId = 2;
    long timeStarted = 12345, lastTxWhenStarted = 12, timeCommitted = timeStarted + 10;
    transaction.setHeader(additionalHeader, masterId, authorId, timeStarted, lastTxWhenStarted, timeCommitted, -1);
    Protocol.TransactionSerializer serializer = new Protocol.TransactionSerializer(transaction);
    ChannelBuffer buffer = new ChannelBufferWrapper(new InMemoryClosableChannel());
    // WHEN serializing the transaction
    serializer.write(buffer);
    // THEN deserializing the same transaction should yield the same data.
    // ... remember that this deserializer doesn't read the data source name string. Read it manually here
    assertEquals(NeoStoreDataSource.DEFAULT_DATA_SOURCE_NAME, Protocol.readString(buffer));
    VersionAwareLogEntryReader<ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader<>();
    TransactionRepresentation readTransaction = new Protocol.TransactionRepresentationDeserializer(reader).read(buffer, ByteBuffer.allocate(1000));
    assertArrayEquals(additionalHeader, readTransaction.additionalHeader());
    assertEquals(masterId, readTransaction.getMasterId());
    assertEquals(authorId, readTransaction.getAuthorId());
    assertEquals(timeStarted, readTransaction.getTimeStarted());
    assertEquals(lastTxWhenStarted, readTransaction.getLatestCommittedTxWhenStarted());
    assertEquals(timeCommitted, readTransaction.getTimeCommitted());
}
Also used : InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) Test(org.junit.Test)

Example 14 with ReadableClosablePositionAwareChannel

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

the class TransactionLogCatchUpWriterTest method verifyCheckpointInLog.

private void verifyCheckpointInLog() throws IOException {
    LogEntryReader<ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader<>(new RecordStorageCommandReaderFactory());
    PhysicalLogFiles logFiles = new PhysicalLogFiles(storeDir, fs);
    final LatestCheckPointFinder checkPointFinder = new LatestCheckPointFinder(logFiles, fs, logEntryReader);
    LatestCheckPointFinder.LatestCheckPoint checkPoint = checkPointFinder.find(0);
    assertNotNull(checkPoint.checkPoint);
    assertTrue(checkPoint.commitsAfterCheckPoint);
}
Also used : RecordStorageCommandReaderFactory(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageCommandReaderFactory) LatestCheckPointFinder(org.neo4j.kernel.recovery.LatestCheckPointFinder) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel) PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles)

Example 15 with ReadableClosablePositionAwareChannel

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

the class RebuildFromLogs method findLastTransactionId.

private long findLastTransactionId(PhysicalLogFiles logFiles, long highestVersion) throws IOException {
    ReadableLogChannel logChannel = new ReadAheadLogChannel(PhysicalLogFile.openForVersion(logFiles, fs, highestVersion, false), NO_MORE_CHANNELS);
    long lastTransactionId = -1;
    LogEntryReader<ReadableClosablePositionAwareChannel> entryReader = new VersionAwareLogEntryReader<>();
    try (IOCursor<CommittedTransactionRepresentation> cursor = new PhysicalTransactionCursor<>(logChannel, entryReader)) {
        while (cursor.next()) {
            lastTransactionId = cursor.get().getCommitEntry().getTxId();
        }
    }
    return lastTransactionId;
}
Also used : PhysicalTransactionCursor(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionCursor) ReadableLogChannel(org.neo4j.kernel.impl.transaction.log.ReadableLogChannel) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) ReadAheadLogChannel(org.neo4j.kernel.impl.transaction.log.ReadAheadLogChannel) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel)

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