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);
}
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);
}
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());
}
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);
}
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;
}
Aggregations