Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rules): rule application occurs within DB transaction to ensure cursor is not closed prematurely #246

Merged
merged 2 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/main/java/io/cryostat/rules/RuleService.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ private IConstrainedMap<String> createRecordingOptions(Rule rule, JFRConnection
return optionsBuilder.build();
}

private void applyRuleToMatchingTargets(Rule rule) {
@Transactional
void applyRuleToMatchingTargets(Rule rule) {
try (Stream<Target> targets = Target.streamAll()) {
targets.filter(
target -> {
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/io/cryostat/rules/ScheduledArchiveJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import io.cryostat.targets.Target;

import jakarta.inject.Inject;
import jakarta.transaction.Transactional;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.jboss.logging.Logger;
import org.quartz.Job;
Expand Down Expand Up @@ -66,8 +67,8 @@ public void execute(JobExecutionContext ctx) throws JobExecutionException {
}
}

private void initPreviousRecordings(
Target target, Rule rule, Queue<String> previousRecordings) {
@Transactional
void initPreviousRecordings(Target target, Rule rule, Queue<String> previousRecordings) {
recordingHelper.listArchivedRecordingObjects().parallelStream()
.forEach(
item -> {
Expand All @@ -87,13 +88,15 @@ private void initPreviousRecordings(
});
}

private void performArchival(ActiveRecording recording, Queue<String> previousRecordings)
@Transactional
void performArchival(ActiveRecording recording, Queue<String> previousRecordings)
throws Exception {
String filename = recordingHelper.saveRecording(recording);
previousRecordings.add(filename);
}

private void pruneArchive(Target target, Queue<String> previousRecordings, String filename)
@Transactional
void pruneArchive(Target target, Queue<String> previousRecordings, String filename)
throws Exception {
recordingHelper.deleteArchivedRecording(target.jvmId, filename);
previousRecordings.remove(filename);
Expand Down
Loading