use of org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo in project neo4j by neo4j.
the class CountsRotationTest method checkPoint.
private void checkPoint(GraphDatabaseAPI db) throws IOException {
TriggerInfo triggerInfo = new SimpleTriggerInfo("test");
db.getDependencyResolver().resolveDependency(CheckPointer.class).forceCheckPoint(triggerInfo);
}
use of org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo in project neo4j by neo4j.
the class TransactionRepresentationCommitProcessIT method commitDuringContinuousCheckpointing.
@Test(timeout = 15000)
public void commitDuringContinuousCheckpointing() throws Exception {
final Index<Node> index;
try (Transaction tx = db.beginTx()) {
index = db.index().forNodes(INDEX_NAME, stringMap(IndexManager.PROVIDER, DummyIndexExtensionFactory.IDENTIFIER));
tx.success();
}
final AtomicBoolean done = new AtomicBoolean();
Workers<Runnable> workers = new Workers<>(getClass().getSimpleName());
for (int i = 0; i < TOTAL_ACTIVE_THREADS; i++) {
workers.start(new Runnable() {
private final ThreadLocalRandom random = ThreadLocalRandom.current();
@Override
public void run() {
while (!done.get()) {
try (Transaction tx = db.beginTx()) {
Node node = db.createNode();
index.add(node, "key", node.getId());
tx.success();
}
randomSleep();
}
}
private void randomSleep() {
try {
Thread.sleep(random.nextInt(50));
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
});
}
Thread.sleep(SECONDS.toMillis(2));
done.set(true);
workers.awaitAndThrowOnError(RuntimeException.class);
NeoStores neoStores = getDependency(RecordStorageEngine.class).testAccessNeoStores();
assertThat("Count store should be rotated once at least", neoStores.getCounts().txId(), greaterThan(0L));
long lastRotationTx = getDependency(CheckPointer.class).forceCheckPoint(new SimpleTriggerInfo("test"));
assertEquals("NeoStore last closed transaction id should be equal last count store rotation transaction id.", neoStores.getMetaDataStore().getLastClosedTransactionId(), lastRotationTx);
assertEquals("Last closed transaction should be last rotated tx in count store", neoStores.getMetaDataStore().getLastClosedTransactionId(), neoStores.getCounts().txId());
}
use of org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo in project neo4j by neo4j.
the class TestRecoveryMultipleDataSources method main.
public static void main(String[] args) throws IOException {
if (args.length != 1) {
exit(1);
}
File storeDir = new File(args[0]);
GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabase(storeDir);
try (Transaction tx = db.beginTx()) {
db.createNode().createRelationshipTo(db.createNode(), MyRelTypes.TEST);
tx.success();
}
((GraphDatabaseAPI) db).getDependencyResolver().resolveDependency(CheckPointer.class).forceCheckPoint(new SimpleTriggerInfo("test"));
try (Transaction tx = db.beginTx()) {
db.index().forNodes("index").add(db.createNode(), storeDir.getAbsolutePath(), db.createNode());
tx.success();
}
exit(0);
}
use of org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo in project neo4j by neo4j.
the class GetStoreRequestHandler method channelRead0.
@Override
protected void channelRead0(ChannelHandlerContext ctx, GetStoreRequest msg) throws Exception {
if (!msg.expectedStoreId().equalToKernelStoreId(dataSource.get().getStoreId())) {
endStoreCopy(SUCCESS, ctx, -1);
} else {
CheckPointer checkPointer = checkPointerSupplier.get();
long lastCheckPointedTx;
try (Resource lock = mutex.storeCopy(() -> checkPointer.tryCheckPoint(new SimpleTriggerInfo("Store copy")));
ResourceIterator<StoreFileMetadata> files = dataSource.get().listStoreFiles(false)) {
lastCheckPointedTx = checkPointer.lastCheckPointedTransactionId();
while (files.hasNext()) {
StoreFileMetadata fileMetadata = files.next();
File file = fileMetadata.file();
log.debug("Sending file " + file);
ctx.writeAndFlush(ResponseMessageType.FILE);
ctx.writeAndFlush(new FileHeader(relativePath(dataSource.get().getStoreDir(), file), fileMetadata.recordSize()));
Optional<PagedFile> existingMapping = pageCache.getExistingMapping(file);
if (existingMapping.isPresent()) {
try (PagedFile pagedFile = existingMapping.get()) {
ctx.writeAndFlush(new FileSender(pagedFile.openReadableByteChannel()));
}
} else {
ctx.writeAndFlush(new FileSender(fs.open(file, "r")));
}
}
}
endStoreCopy(SUCCESS, ctx, lastCheckPointedTx);
}
protocol.expect(State.MESSAGE_TYPE);
}
use of org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo in project neo4j by neo4j.
the class IndexCreationTest method verifyThatIndexCreationTransactionIsTheFirstOne.
private void verifyThatIndexCreationTransactionIsTheFirstOne() throws Exception {
PhysicalLogFile pLogFile = db.getDependencyResolver().resolveDependency(PhysicalLogFile.class);
long version = db.getDependencyResolver().resolveDependency(LogVersionRepository.class).getCurrentLogVersion();
db.getDependencyResolver().resolveDependency(LogRotation.class).rotateLogFile();
db.getDependencyResolver().resolveDependency(CheckPointer.class).forceCheckPoint(new SimpleTriggerInfo("test"));
ReadableLogChannel logChannel = pLogFile.getReader(LogPosition.start(version));
final AtomicBoolean success = new AtomicBoolean(false);
try (IOCursor<LogEntry> cursor = new LogEntryCursor(new VersionAwareLogEntryReader<>(), logChannel)) {
List<StorageCommand> commandsInFirstEntry = new ArrayList<>();
boolean startFound = false;
while (cursor.next()) {
LogEntry entry = cursor.get();
if (entry instanceof LogEntryStart) {
if (startFound) {
throw new IllegalArgumentException("More than one start entry");
}
startFound = true;
}
if (startFound && entry instanceof LogEntryCommand) {
commandsInFirstEntry.add(entry.<LogEntryCommand>as().getXaCommand());
}
if (entry instanceof LogEntryCommit) {
// The first COMMIT
assertTrue(startFound);
assertFalse("Index creation transaction wasn't the first one", commandsInFirstEntry.isEmpty());
List<StorageCommand> createCommands = Iterators.asList(new FilteringIterator<>(commandsInFirstEntry.iterator(), item -> item instanceof IndexDefineCommand));
assertEquals(1, createCommands.size());
success.set(true);
break;
}
}
}
assertTrue("Didn't find any commit record in log " + version, success.get());
}
Aggregations