From 53ea034b0e8ec060684a2e85bfda0f4b4063922d Mon Sep 17 00:00:00 2001 From: Andrew Azores Date: Fri, 19 Jan 2024 16:07:59 -0500 Subject: [PATCH] fix(rules): rule application occurs within DB transaction to ensure cursor is not closed prematurely (#246) --- src/main/java/io/cryostat/rules/RuleService.java | 3 ++- .../java/io/cryostat/rules/ScheduledArchiveJob.java | 11 +++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/cryostat/rules/RuleService.java b/src/main/java/io/cryostat/rules/RuleService.java index ed0ef0f4b..6e3d67748 100644 --- a/src/main/java/io/cryostat/rules/RuleService.java +++ b/src/main/java/io/cryostat/rules/RuleService.java @@ -189,7 +189,8 @@ private IConstrainedMap createRecordingOptions(Rule rule, JFRConnection return optionsBuilder.build(); } - private void applyRuleToMatchingTargets(Rule rule) { + @Transactional + void applyRuleToMatchingTargets(Rule rule) { try (Stream targets = Target.streamAll()) { targets.filter( target -> { diff --git a/src/main/java/io/cryostat/rules/ScheduledArchiveJob.java b/src/main/java/io/cryostat/rules/ScheduledArchiveJob.java index 31baeb15d..742dc099e 100644 --- a/src/main/java/io/cryostat/rules/ScheduledArchiveJob.java +++ b/src/main/java/io/cryostat/rules/ScheduledArchiveJob.java @@ -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; @@ -66,8 +67,8 @@ public void execute(JobExecutionContext ctx) throws JobExecutionException { } } - private void initPreviousRecordings( - Target target, Rule rule, Queue previousRecordings) { + @Transactional + void initPreviousRecordings(Target target, Rule rule, Queue previousRecordings) { recordingHelper.listArchivedRecordingObjects().parallelStream() .forEach( item -> { @@ -87,13 +88,15 @@ private void initPreviousRecordings( }); } - private void performArchival(ActiveRecording recording, Queue previousRecordings) + @Transactional + void performArchival(ActiveRecording recording, Queue previousRecordings) throws Exception { String filename = recordingHelper.saveRecording(recording); previousRecordings.add(filename); } - private void pruneArchive(Target target, Queue previousRecordings, String filename) + @Transactional + void pruneArchive(Target target, Queue previousRecordings, String filename) throws Exception { recordingHelper.deleteArchivedRecording(target.jvmId, filename); previousRecordings.remove(filename);