Skip to content

Commit

Permalink
Remove concurrency not required
Browse files Browse the repository at this point in the history
Signed-off-by: Siddhant Deshmukh <[email protected]>
  • Loading branch information
deshsidd committed Aug 28, 2024
1 parent 6be1a8b commit f1aec84
Showing 1 changed file with 7 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@
public final class QueryInsightsListener extends SearchRequestOperationsListener {
private static final ToXContent.Params FORMAT_PARAMS = new ToXContent.MapParams(Collections.singletonMap("pretty", "false"));

private final Object stateLock = new Object(); // Lock to synchronize service start/stop

private static final Logger log = LogManager.getLogger(QueryInsightsListener.class);

private final QueryInsightsService queryInsightsService;
Expand Down Expand Up @@ -137,16 +135,13 @@ public void setSearchQueryMetricsEnabled(boolean searchQueryMetricsEnabled) {
private void updateQueryInsightsState() {
boolean anyFeatureEnabled = queryInsightsService.isAnyFeatureEnabled();

// Handles multiple feature enabled/disabled simultaneously
synchronized (stateLock) {
if (anyFeatureEnabled && !super.isEnabled()) {
super.setEnabled(true);
queryInsightsService.stop(); // Ensures a clean restart
queryInsightsService.start();
} else if (!anyFeatureEnabled && super.isEnabled()) {
super.setEnabled(false);
queryInsightsService.stop();
}
if (anyFeatureEnabled && !super.isEnabled()) {
super.setEnabled(true);
queryInsightsService.stop(); // Ensures a clean restart
queryInsightsService.start();
} else if (!anyFeatureEnabled && super.isEnabled()) {
super.setEnabled(false);
queryInsightsService.stop();
}
}

Expand Down

0 comments on commit f1aec84

Please sign in to comment.