use of org.neo4j.kernel.impl.transaction.TransactionRepresentation in project neo4j by neo4j.
the class BatchingTransactionAppenderTest method batchOf.
private TransactionToApply batchOf(TransactionRepresentation... transactions) {
TransactionToApply first = null, last = null;
for (TransactionRepresentation transaction : transactions) {
TransactionToApply tx = new TransactionToApply(transaction);
if (first == null) {
first = last = tx;
} else {
last.next(tx);
last = tx;
}
}
return first;
}
use of org.neo4j.kernel.impl.transaction.TransactionRepresentation in project neo4j by neo4j.
the class ApplyRecoveredTransactionsTest method applyExternalTransaction.
private void applyExternalTransaction(long transactionId, Command... commands) throws Exception {
LockService lockService = mock(LockService.class);
when(lockService.acquireNodeLock(anyLong(), any(LockService.LockType.class))).thenReturn(LockService.NO_LOCK);
when(lockService.acquireRelationshipLock(anyLong(), any(LockService.LockType.class))).thenReturn(LockService.NO_LOCK);
NeoStoreBatchTransactionApplier applier = new NeoStoreBatchTransactionApplier(neoStores, mock(CacheAccessBackDoor.class), lockService);
TransactionRepresentation tx = new PhysicalTransactionRepresentation(Arrays.asList(commands));
CommandHandlerContract.apply(applier, txApplier -> {
tx.accept(txApplier);
return false;
}, new TransactionToApply(tx, transactionId));
}
use of org.neo4j.kernel.impl.transaction.TransactionRepresentation in project neo4j by neo4j.
the class MasterClient214 method commit.
@Override
public Response<Long> commit(RequestContext context, TransactionRepresentation tx) {
Serializer serializer = new Protocol.TransactionSerializer(tx);
Deserializer<Long> deserializer = (buffer, temporaryBuffer) -> buffer.readLong();
return sendRequest(requestTypes.type(HaRequestTypes.Type.COMMIT), context, serializer, deserializer);
}
use of org.neo4j.kernel.impl.transaction.TransactionRepresentation in project neo4j by neo4j.
the class SlaveTransactionCommitProcess method commit.
@Override
public long commit(TransactionToApply batch, CommitEvent commitEvent, TransactionApplicationMode mode) throws TransactionFailureException {
if (batch.next() != null) {
throw new IllegalArgumentException("Only supports single-commit on slave --> master");
}
try {
TransactionRepresentation representation = batch.transactionRepresentation();
RequestContext context = requestContextFactory.newRequestContext(representation.getLockSessionId());
try (Response<Long> response = master.commit(context, representation)) {
return response.response();
}
} catch (IOException e) {
throw new TransactionFailureException(Status.Transaction.TransactionCommitFailed, e, "Could not commit transaction on the master");
} catch (ComException e) {
throw new TransientTransactionFailureException("Cannot commit this transaction on the master. " + "The master is either down, or we have network connectivity problems.", e);
}
}
use of org.neo4j.kernel.impl.transaction.TransactionRepresentation 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());
}
Aggregations