use of org.neo4j.com.Response 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.com.Response 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.com.Response 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.com.Response in project neo4j by neo4j.
the class SwitchToSlave method copyStoreFromMaster.
void copyStoreFromMaster(MasterClient masterClient, CancellationRequest cancellationRequest, MoveAfterCopy moveAfterCopy) throws Throwable {
try {
userLog.info("Copying store from master");
StoreCopyClient.StoreCopyRequester requester = new StoreCopyClient.StoreCopyRequester() {
@Override
public Response<?> copyStore(StoreWriter writer) {
return masterClient.copyStore(new RequestContext(0, config.get(ClusterSettings.server_id).toIntegerIndex(), 0, BASE_TX_ID, 0), writer);
}
@Override
public void done() {
// Nothing to clean up here
}
};
MoveAfterCopy moveAfterCopyWithLogging = (moves, fromDirectory, toDirectory) -> {
userLog.info("Copied store from master to " + fromDirectory);
msgLog.info("Starting post copy operation to move store from " + fromDirectory + " to " + storeDir);
moveAfterCopy.move(moves, fromDirectory, toDirectory);
};
storeCopyClient.copyStore(requester, cancellationRequest, moveAfterCopyWithLogging);
startServicesAgain();
userLog.info("Finished copying store from master");
} catch (Throwable t) {
// Delete store so that we can copy from master without conflicts next time
cleanStoreDir();
throw t;
}
}
use of org.neo4j.com.Response in project neo4j by neo4j.
the class MasterClient214 method createPropertyKey.
@Override
public Response<Integer> createPropertyKey(RequestContext context, final String name) {
Serializer serializer = buffer -> writeString(buffer, name);
Deserializer<Integer> deserializer = (buffer, temporaryBuffer) -> buffer.readInt();
return sendRequest(requestTypes.type(HaRequestTypes.Type.CREATE_PROPERTY_KEY), context, serializer, deserializer);
}
Aggregations