-
Notifications
You must be signed in to change notification settings - Fork 13
fix(sql): Bugfixes for sql matching stats #3915
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
Changes from all commits
be1aa2b
d679125
b36ca6a
e75125e
3db299f
1e2bc61
4efd8d0
bfc174a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,18 +31,15 @@ public class ManagedConnection implements Managed { | |
| @Override | ||
| public void start() throws Exception { | ||
| dataSource = connection.createDataSource(healthCheckRegistry); | ||
|
|
||
| try { | ||
| log.debug("TEST connecting to {}", connection.getJdbcConnectionUrl()); | ||
| if (dataSource.getConnection().isValid(100)) { | ||
| if (dataSource.getConnection().isValid(1000)) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Die 1000 ist ein Timeout oder?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. genau, der geht hier aber nur auf die connection. Denke, wenn die Verbindung nach 1sek nicht als valide aufgebaut werden kann ist da was kaputt |
||
| log.info("SUCCESS connecting to {}", connection.getJdbcConnectionUrl()); | ||
| } | ||
| else { | ||
| } else { | ||
| log.error("FAILED connecting to {}. Connection did not become valid.", connection.getJdbcConnectionUrl()); | ||
| } | ||
| } | ||
| catch (SQLException exception) { | ||
| log.error("FAILED connecting to {}", connection.getJdbcConnectionUrl(), exception); | ||
| } catch (SQLException exception) { | ||
| throw new RuntimeException("FAILED connecting to %s".formatted(connection.getJdbcConnectionUrl()), exception); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,78 +1,95 @@ | ||
| package com.bakdata.conquery.mode.local; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collection; | ||
| import java.util.List; | ||
| import java.util.concurrent.*; | ||
| import java.util.Map; | ||
| import java.util.concurrent.Executors; | ||
| import java.util.concurrent.Future; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| import com.bakdata.conquery.models.datasets.Dataset; | ||
| import com.bakdata.conquery.models.datasets.concepts.Concept; | ||
| import com.bakdata.conquery.models.datasets.concepts.tree.TreeConcept; | ||
| import com.bakdata.conquery.models.identifiable.ids.specific.ConceptId; | ||
| import com.bakdata.conquery.models.jobs.Job; | ||
| import com.bakdata.conquery.sql.conquery.SqlMatchingStats; | ||
| import com.google.common.base.Stopwatch; | ||
| import com.google.common.util.concurrent.Futures; | ||
| import com.google.common.util.concurrent.ListenableFuture; | ||
| import com.google.common.util.concurrent.ListeningExecutorService; | ||
| import com.google.common.util.concurrent.MoreExecutors; | ||
| import lombok.Data; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.ToString; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.apache.commons.lang3.builder.ToStringExclude; | ||
| import org.checkerframework.checker.nullness.qual.Nullable; | ||
| import org.apache.commons.collections4.map.HashedMap; | ||
|
|
||
| @Slf4j | ||
| @Data | ||
|
thoniTUB marked this conversation as resolved.
|
||
| @EqualsAndHashCode(callSuper = false) | ||
| public class UpdateMatchingStatsSqlJob extends Job { | ||
|
|
||
| @ToString.Exclude | ||
| private final List<Concept<?>> concepts; | ||
| private final Dataset dataset; | ||
| @ToString.Exclude | ||
| private final List<Concept<?>> concepts; | ||
| private final Dataset dataset; | ||
|
|
||
| @ToString.Exclude | ||
| private final SqlMatchingStats matchingStats; | ||
| @ToString.Exclude | ||
| private final SqlMatchingStats matchingStats; | ||
|
|
||
|
|
||
| @Override | ||
| public void execute() throws Exception { | ||
| @Override | ||
| public void execute() throws Exception { | ||
|
|
||
| log.info("BEGIN collecting SQL matching stats for {}", dataset); | ||
| log.info("BEGIN collecting SQL matching stats for {}", dataset); | ||
|
|
||
| Stopwatch stopwatch = Stopwatch.createStarted(); | ||
| Stopwatch stopwatch = Stopwatch.createStarted(); | ||
|
|
||
| ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newVirtualThreadPerTaskExecutor()); | ||
| ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(getMatchingStats().getMatchingStatsWorkers())); | ||
|
|
||
| List<ListenableFuture<?>> jobs = new ArrayList<>(); | ||
| Map<ConceptId, ListenableFuture<?>> jobsByConcept = new HashedMap<>(); | ||
| Collection<ListenableFuture<?>> jobs = jobsByConcept.values(); | ||
|
|
||
| for (Concept<?> concept : concepts) { | ||
| if (!(concept instanceof TreeConcept)) { | ||
| continue; | ||
| } | ||
| jobs.add(matchingStats.collectMatchingStatsForConcept((TreeConcept) concept, executorService)); | ||
| } | ||
| for (Concept<?> concept : concepts) { | ||
| if (concept instanceof TreeConcept) { | ||
| ListenableFuture<?> job = matchingStats.collectMatchingStatsForConcept((TreeConcept) concept, executorService, getMatchingStats().getMatchingStatsRetries()); | ||
|
|
||
| ListenableFuture<List<@Nullable Object>> all = Futures.allAsList(jobs); | ||
| job.addListener( | ||
| () -> { | ||
| if (job.state().equals(Future.State.FAILED)) { | ||
| log.warn("FAILED to collect SQL matching stats for {}", concept, job.exceptionNow()); | ||
| } | ||
| }, MoreExecutors.directExecutor()); | ||
|
|
||
| while (!all.isDone()) { | ||
| if (isCancelled()) { | ||
| all.cancel(true); | ||
|
awildturtok marked this conversation as resolved.
|
||
| log.debug("CANCELLED update matching stats for {}", getDataset(), all.exceptionNow()); | ||
| return; | ||
| } | ||
| jobsByConcept.put(concept.getId(), job); | ||
| } | ||
| } | ||
|
|
||
| all.get(5, TimeUnit.SECONDS); | ||
| log.trace("WAITING for matching stats to finish {}", getDataset()); | ||
| while (jobs.stream().anyMatch(job -> job.state().equals(Future.State.RUNNING))) { | ||
| if (isCancelled()) { | ||
| for (ListenableFuture<?> job : jobs) { | ||
| job.cancel(true); | ||
| } | ||
| } | ||
|
|
||
| if (all.state().equals(Future.State.FAILED)) { | ||
| log.error("FAILED update matching stats for {}", getDataset(), all.exceptionNow()); | ||
| return; | ||
| } | ||
| } | ||
| for (ListenableFuture<?> someJob : jobs) { | ||
| if (someJob.isDone()) { | ||
| continue; | ||
| } | ||
|
|
||
| log.debug("DONE collecting SQL matching stats for {} within {}", dataset, stopwatch); | ||
| } | ||
| try { | ||
| someJob.get(30, TimeUnit.SECONDS); | ||
| } catch (Exception e) { | ||
|
awildturtok marked this conversation as resolved.
|
||
| // intentionally left blank | ||
| } | ||
|
|
||
| @Override | ||
| public String getLabel() { | ||
| return "Collect matching stats for %s (%s concepts)".formatted(dataset.getName(), concepts.size()); | ||
| } | ||
| log.debug("WAITING for {} matching stats to finish.", jobs.stream().filter(job -> job.state().equals(Future.State.RUNNING)).count()); | ||
| } | ||
| } | ||
|
|
||
| log.debug("DONE collecting SQL matching stats for {} within {}", dataset, stopwatch); | ||
| } | ||
|
|
||
| @Override | ||
| public String getLabel() { | ||
| return "Collect matching stats for %s (%s concepts)".formatted(dataset.getName(), concepts.size()); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.