use of org.neo4j.helpers.collection.Visitor in project neo4j by neo4j.
the class RecoveryTest method writeSomeData.
private void writeSomeData(File file, Visitor<Pair<LogEntryWriter, Consumer<LogPositionMarker>>, IOException> visitor) throws IOException {
try (LogVersionedStoreChannel versionedStoreChannel = new PhysicalLogVersionedStoreChannel(fileSystemRule.get().open(file, "rw"), logVersion, CURRENT_LOG_VERSION);
final PositionAwarePhysicalFlushableChannel writableLogChannel = new PositionAwarePhysicalFlushableChannel(versionedStoreChannel)) {
writeLogHeader(writableLogChannel, logVersion, 2L);
Consumer<LogPositionMarker> consumer = marker -> {
try {
writableLogChannel.getCurrentPosition(marker);
} catch (IOException e) {
throw new RuntimeException(e);
}
};
LogEntryWriter first = new LogEntryWriter(writableLogChannel);
visitor.visit(Pair.of(first, consumer));
}
}
use of org.neo4j.helpers.collection.Visitor in project neo4j by neo4j.
the class ResponsePacker method packTransactionStreamResponse.
public <T> Response<T> packTransactionStreamResponse(RequestContext context, T response) {
final long toStartFrom = context.lastAppliedTransaction() + 1;
final long toEndAt = transactionIdStore.getLastCommittedTransactionId();
TransactionStream transactions = visitor -> {
if (toStartFrom > BASE_TX_ID && toStartFrom <= toEndAt) {
extractTransactions(toStartFrom, filterVisitor(visitor, toEndAt));
}
};
return new TransactionStreamResponse<>(response, storeId.get(), transactions, ResourceReleaser.NO_OP);
}
use of org.neo4j.helpers.collection.Visitor in project neo4j by neo4j.
the class ResponsePackerIT method shouldPackTheHighestTxCommittedAsObligation.
@Test
public void shouldPackTheHighestTxCommittedAsObligation() throws Exception {
// GIVEN
LogicalTransactionStore transactionStore = mock(LogicalTransactionStore.class);
FileSystemAbstraction fs = fsRule.get();
PageCache pageCache = pageCacheRule.getPageCache(fs);
try (NeoStores neoStore = createNeoStore(fs, pageCache)) {
MetaDataStore store = neoStore.getMetaDataStore();
store.transactionCommitted(2, 111, BASE_TX_COMMIT_TIMESTAMP);
store.transactionCommitted(3, 222, BASE_TX_COMMIT_TIMESTAMP);
store.transactionCommitted(4, 333, BASE_TX_COMMIT_TIMESTAMP);
store.transactionCommitted(5, 444, BASE_TX_COMMIT_TIMESTAMP);
store.transactionCommitted(6, 555, BASE_TX_COMMIT_TIMESTAMP);
// skip 7 to emulate the fact we have an hole in the committed tx ids list
final long expectedTxId = 8L;
store.transactionCommitted(expectedTxId, 777, BASE_TX_COMMIT_TIMESTAMP);
ResponsePacker packer = new ResponsePacker(transactionStore, store, Suppliers.singleton(newStoreIdForCurrentVersion()));
// WHEN
Response<Object> response = packer.packTransactionObligationResponse(new RequestContext(0, 0, 0, 0, 0), new Object());
// THEN
assertTrue(response instanceof TransactionObligationResponse);
((TransactionObligationResponse) response).accept(new Response.Handler() {
@Override
public void obligation(long txId) throws IOException {
assertEquals(expectedTxId, txId);
}
@Override
public Visitor<CommittedTransactionRepresentation, Exception> transactions() {
throw new UnsupportedOperationException("not expected");
}
});
}
}
use of org.neo4j.helpers.collection.Visitor in project neo4j by neo4j.
the class ResponsePackerTest method shouldHaveFixedTargetTransactionIdEvenIfLastTransactionIdIsMoving.
@Test
public void shouldHaveFixedTargetTransactionIdEvenIfLastTransactionIdIsMoving() throws Exception {
// GIVEN
LogicalTransactionStore transactionStore = mock(LogicalTransactionStore.class);
long lastAppliedTransactionId = 5L;
TransactionCursor endlessCursor = new EndlessCursor(lastAppliedTransactionId + 1);
when(transactionStore.getTransactions(anyLong())).thenReturn(endlessCursor);
final long targetTransactionId = 8L;
final TransactionIdStore transactionIdStore = new DeadSimpleTransactionIdStore(targetTransactionId, 0, BASE_TX_COMMIT_TIMESTAMP, 0, 0);
ResponsePacker packer = new ResponsePacker(transactionStore, transactionIdStore, Suppliers.singleton(StoreIdTestFactory.newStoreIdForCurrentVersion()));
// WHEN
Response<Object> response = packer.packTransactionStreamResponse(requestContextStartingAt(5L), null);
final AtomicLong nextExpectedVisit = new AtomicLong(lastAppliedTransactionId);
response.accept(new Response.Handler() {
@Override
public void obligation(long txId) throws IOException {
fail("Should not be called");
}
@Override
public Visitor<CommittedTransactionRepresentation, Exception> transactions() {
return new Visitor<CommittedTransactionRepresentation, Exception>() {
@Override
public boolean visit(CommittedTransactionRepresentation element) {
// THEN
long txId = element.getCommitEntry().getTxId();
assertThat(txId, lessThanOrEqualTo(targetTransactionId));
assertEquals(nextExpectedVisit.incrementAndGet(), txId);
// Move the target transaction id forward one step, effectively always keeping it out of reach
transactionIdStore.setLastCommittedAndClosedTransactionId(transactionIdStore.getLastCommittedTransactionId() + 1, 0, BASE_TX_COMMIT_TIMESTAMP, 3, 4);
return true;
}
};
}
});
}
use of org.neo4j.helpers.collection.Visitor in project neo4j by neo4j.
the class MadeUpServerImplementation method streamBackTransactions.
@Override
public Response<Integer> streamBackTransactions(int responseToSendBack, final int txCount) {
TransactionStream transactions = new TransactionStream() {
@Override
public void accept(Visitor<CommittedTransactionRepresentation, Exception> visitor) throws Exception {
for (int i = 1; i <= txCount; i++) {
CommittedTransactionRepresentation transaction = createTransaction(TransactionIdStore.BASE_TX_ID + i);
visitor.visit(transaction);
}
}
};
return new TransactionStreamResponse<>(responseToSendBack, storeIdToRespondWith, transactions, ResourceReleaser.NO_OP);
}
Aggregations