use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.
the class TxPullRequestHandlerTest method shouldRespondWithoutTransactionsIfTheyDoNotExist.
@Test
public void shouldRespondWithoutTransactionsIfTheyDoNotExist() throws Exception {
// given
StoreId storeId = new StoreId(1, 2, 3, 4);
TransactionIdStore transactionIdStore = mock(TransactionIdStore.class);
when(transactionIdStore.getLastCommittedTransactionId()).thenReturn(15L);
LogicalTransactionStore logicalTransactionStore = mock(LogicalTransactionStore.class);
when(logicalTransactionStore.getTransactions(14L)).thenThrow(new NoSuchTransactionException(14));
TxPullRequestHandler txPullRequestHandler = new TxPullRequestHandler(new CatchupServerProtocol(), () -> storeId, () -> true, () -> transactionIdStore, () -> logicalTransactionStore, BATCH_SIZE, new Monitors(), logProvider);
// when
txPullRequestHandler.channelRead0(context, new TxPullRequest(13, storeId));
// then
verify(context, never()).write(ResponseMessageType.TX);
verify(context).write(ResponseMessageType.TX_STREAM_FINISHED);
verify(context).write(new TxStreamFinishedResponse(E_TRANSACTION_PRUNED, 15L));
logProvider.assertAtLeastOnce(inLog(TxPullRequestHandler.class).info("Failed to serve TxPullRequest for tx %d because the transaction does not exist.", 14L));
}
use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.
the class RemoteStoreTest method shouldCopyStoreFilesAndPullTransactions.
@Test
public void shouldCopyStoreFilesAndPullTransactions() throws Exception {
// given
StoreId storeId = new StoreId(1, 2, 3, 4);
StoreCopyClient storeCopyClient = mock(StoreCopyClient.class);
TxPullClient txPullClient = mock(TxPullClient.class);
when(txPullClient.pullTransactions(any(), any(), anyLong(), any())).thenReturn(new TxPullRequestResult(SUCCESS_END_OF_STREAM, 13));
TransactionLogCatchUpWriter writer = mock(TransactionLogCatchUpWriter.class);
RemoteStore remoteStore = new RemoteStore(NullLogProvider.getInstance(), mock(FileSystemAbstraction.class), null, storeCopyClient, txPullClient, factory(writer), new Monitors());
// when
MemberId localhost = new MemberId(UUID.randomUUID());
remoteStore.copy(localhost, storeId, new File("destination"));
// then
verify(storeCopyClient).copyStoreFiles(eq(localhost), eq(storeId), any(StoreFileStreams.class));
verify(txPullClient).pullTransactions(eq(localhost), eq(storeId), anyLong(), any(TxPullResponseListener.class));
}
use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.
the class StoreCopyClient method writeTransactionsToActiveLogFile.
private void writeTransactionsToActiveLogFile(File tempStoreDir, Response<?> response) throws Exception {
LifeSupport life = new LifeSupport();
try {
// Start the log and appender
PhysicalLogFiles logFiles = new PhysicalLogFiles(tempStoreDir, fs);
LogHeaderCache logHeaderCache = new LogHeaderCache(10);
ReadOnlyLogVersionRepository logVersionRepository = new ReadOnlyLogVersionRepository(pageCache, tempStoreDir);
ReadOnlyTransactionIdStore readOnlyTransactionIdStore = new ReadOnlyTransactionIdStore(pageCache, tempStoreDir);
LogFile logFile = life.add(new PhysicalLogFile(fs, logFiles, Long.MAX_VALUE, /*don't rotate*/
readOnlyTransactionIdStore::getLastCommittedTransactionId, logVersionRepository, new Monitors().newMonitor(PhysicalLogFile.Monitor.class), logHeaderCache));
life.start();
// Just write all transactions to the active log version. Remember that this is after a store copy
// where there are no logs, and the transaction stream we're about to write will probably contain
// transactions that goes some time back, before the last committed transaction id. So we cannot
// use a TransactionAppender, since it has checks for which transactions one can append.
FlushableChannel channel = logFile.getWriter();
final TransactionLogWriter writer = new TransactionLogWriter(new LogEntryWriter(channel));
final AtomicLong firstTxId = new AtomicLong(BASE_TX_ID);
response.accept(new Response.Handler() {
@Override
public void obligation(long txId) throws IOException {
throw new UnsupportedOperationException("Shouldn't be called");
}
@Override
public Visitor<CommittedTransactionRepresentation, Exception> transactions() {
return transaction -> {
long txId = transaction.getCommitEntry().getTxId();
if (firstTxId.compareAndSet(BASE_TX_ID, txId)) {
monitor.startReceivingTransactions(txId);
}
writer.append(transaction.getTransactionRepresentation(), txId);
return false;
};
}
});
long endTxId = firstTxId.get();
if (endTxId != BASE_TX_ID) {
monitor.finishReceivingTransactions(endTxId);
}
long currentLogVersion = logVersionRepository.getCurrentLogVersion();
writer.checkPoint(new LogPosition(currentLogVersion, LOG_HEADER_SIZE));
// And since we write this manually we need to set the correct transaction id in the
// header of the log that we just wrote.
File currentLogFile = logFiles.getLogFileForVersion(currentLogVersion);
writeLogHeader(fs, currentLogFile, currentLogVersion, max(BASE_TX_ID, endTxId - 1));
if (!forensics) {
// since we just create new log and put checkpoint into it with offset equals to
// LOG_HEADER_SIZE we need to update last transaction offset to be equal to this newly defined max
// offset otherwise next checkpoint that use last transaction offset will be created for non
// existing offset that is in most of the cases bigger than new log size.
// Recovery will treat that as last checkpoint and will not try to recover store till new
// last closed transaction offset will not overcome old one. Till that happens it will be
// impossible for recovery process to restore the store
File neoStore = new File(tempStoreDir, MetaDataStore.DEFAULT_NAME);
MetaDataStore.setRecord(pageCache, neoStore, MetaDataStore.Position.LAST_CLOSED_TRANSACTION_LOG_BYTE_OFFSET, LOG_HEADER_SIZE);
}
} finally {
life.shutdown();
}
}
use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.
the class MonitoredBoltWorkerFactoryTest method shouldReportStartedSessions.
@Test
public void shouldReportStartedSessions() {
int workersCount = 42;
Monitors monitors = new Monitors();
CountingSessionMonitor monitor = new CountingSessionMonitor();
monitors.addMonitorListener(monitor);
WorkerFactory mockWorkers = mock(WorkerFactory.class);
when(mockWorkers.newWorker(anyObject(), any())).thenReturn(mock(BoltWorker.class));
MonitoredWorkerFactory workerFactory = new MonitoredWorkerFactory(monitors, mockWorkers, systemClock());
for (int i = 0; i < workersCount; i++) {
workerFactory.newWorker(CONNECTION_DESCRIPTOR);
}
assertEquals(workersCount, monitor.sessionsStarted);
}
use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.
the class MonitoredBoltWorkerFactoryTest method shouldNotWrapWithMonitoredSessionIfNobodyIsListening.
@Test
public void shouldNotWrapWithMonitoredSessionIfNobodyIsListening() throws Throwable {
// Given
// Monitoring adds GC overhead, so we only want to do the work involved
// if someone has actually registered a listener. We still allow plugging
// monitoring in at runtime, but it will only apply to sessions started
// after monitor listeners are added
WorkerFactory workerFactory = mock(WorkerFactory.class);
BoltWorker innerSession = mock(BoltWorker.class);
when(workerFactory.newWorker(anyObject(), anyObject())).thenReturn(innerSession);
Monitors monitors = new Monitors();
MonitoredWorkerFactory monitoredWorkerFactory = new MonitoredWorkerFactory(monitors, workerFactory, Clocks.fakeClock());
// When
BoltWorker worker = monitoredWorkerFactory.newWorker(CONNECTION_DESCRIPTOR);
// Then
assertEquals(innerSession, worker);
// But when I register a listener
monitors.addMonitorListener(new CountingSessionMonitor());
// Then new sessions should be monitored
assertThat(monitoredWorkerFactory.newWorker(CONNECTION_DESCRIPTOR), instanceOf(MonitoredBoltWorker.class));
}
Aggregations