Skip to content

Commit

Permalink
Use advisory locks to avoid duplicate metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
nineinchnick committed Sep 21, 2022
1 parent 9a42188 commit 990dd8e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ public void finishExecution(String uniqueName, String benchmarkSequenceId, Strin
private List<Measurement> normalizeMeasurements(List<FlatMeasurement> input)
{
// use a lookup map to avoid building a complex SQL query that compares attributes list
// acquire a lock to avoid adding multiple metrics with same name and same attributes
metricRepo.lock();
Map<Metric, Metric> metrics = new HashMap<>();
metricRepo.findAll().forEach(metric -> metrics.put(metric, metric));
Map<Metric, List<FlatMeasurement>> groups = input.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@

import io.trino.benchto.service.model.Metric;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

@Repository
public interface MetricRepo
extends JpaRepository<Metric, Long>
{
@Query(value = "select pg_advisory_xact_lock(1)", nativeQuery = true)
void lock();
}

0 comments on commit 990dd8e

Please sign in to comment.