Skip to content

Commit

Permalink
fix(rules): rule application occurs within DB transaction to ensure c…
Browse files Browse the repository at this point in the history
…ursor is not closed prematurely (#246)
  • Loading branch information
andrewazores authored Jan 19, 2024
1 parent 34c7a6b commit 53ea034
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
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

0 comments on commit 53ea034

Please sign in to comment.