From ecf94aa8226111877b5ee830ca1a709f2137772c Mon Sep 17 00:00:00 2001 From: Laura Schanno Date: Wed, 6 May 2026 20:27:21 -0400 Subject: [PATCH 1/2] Fix QueryLimiter CDI injection Ensure the QueryLimiter is properly injected into the CachedResultsBean and the QueryExpirationBean. Fixes #3536 --- .../results/cached/CachedResultsBean.java | 1 + .../query/cache/QueryExpirationBean.java | 36 +++++-------------- .../webservice/query/limit/QueryLimiter.java | 4 +++ .../query/cache/QueryExpirationBeanTest.java | 13 +++---- 4 files changed, 21 insertions(+), 33 deletions(-) diff --git a/web-services/cached-results/src/main/java/datawave/webservice/results/cached/CachedResultsBean.java b/web-services/cached-results/src/main/java/datawave/webservice/results/cached/CachedResultsBean.java index f416641273e..39a2bcaa377 100644 --- a/web-services/cached-results/src/main/java/datawave/webservice/results/cached/CachedResultsBean.java +++ b/web-services/cached-results/src/main/java/datawave/webservice/results/cached/CachedResultsBean.java @@ -240,6 +240,7 @@ public class CachedResultsBean { private AccumuloConnectionRequestBean accumuloConnectionRequestBean; @Inject + @SpringBean(name = "queryLimiter") private QueryLimiter queryLimiter; protected static final String COMMA = ","; diff --git a/web-services/query/src/main/java/datawave/webservice/query/cache/QueryExpirationBean.java b/web-services/query/src/main/java/datawave/webservice/query/cache/QueryExpirationBean.java index 8db89c2ff18..330dfa69d52 100644 --- a/web-services/query/src/main/java/datawave/webservice/query/cache/QueryExpirationBean.java +++ b/web-services/query/src/main/java/datawave/webservice/query/cache/QueryExpirationBean.java @@ -43,45 +43,27 @@ public class QueryExpirationBean { private static final Logger log = Logger.getLogger(QueryExpirationBean.class); - private QueryCache queryCache; - private QueryExpirationProperties config; - private AccumuloConnectionFactory connectionFactory; - private CreatedQueryLogicCacheBean queryLogicCacheBean; - private QueryMetricsBean metricsBean; - private QueryLimiter queryLimiter; - - private boolean clearAll = false; - @Inject - public void setQueryCache(QueryCache cache) { - this.queryCache = cache; - } + private QueryCache queryCache; @Inject @SpringBean(refreshable = true) - public void setQueryExpirationProperties(QueryExpirationProperties properties) { - this.config = properties; - } + private QueryExpirationProperties config; @Inject - public void setConnectionFactory(AccumuloConnectionFactory connectionFactory) { - this.connectionFactory = connectionFactory; - } + private AccumuloConnectionFactory connectionFactory; @Inject - public void setCreatedQueryLogicCacheBean(CreatedQueryLogicCacheBean cacheBean) { - this.queryLogicCacheBean = cacheBean; - } + private CreatedQueryLogicCacheBean queryLogicCacheBean; @Inject - public void setQueryMetricsBean(QueryMetricsBean metrics) { - this.metricsBean = metrics; - } + private QueryMetricsBean metricsBean; @Inject - public void setQueryLimiter(QueryLimiter queryLimiter) { - this.queryLimiter = queryLimiter; - } + @SpringBean(name = "queryLimiter") + private QueryLimiter queryLimiter; + + private boolean clearAll = false; @PostConstruct public void init() { diff --git a/web-services/query/src/main/java/datawave/webservice/query/limit/QueryLimiter.java b/web-services/query/src/main/java/datawave/webservice/query/limit/QueryLimiter.java index 32c320029bd..8e1f3dff263 100644 --- a/web-services/query/src/main/java/datawave/webservice/query/limit/QueryLimiter.java +++ b/web-services/query/src/main/java/datawave/webservice/query/limit/QueryLimiter.java @@ -91,6 +91,8 @@ public void setup() { log.debug("Initializing with zookeeperConfig: '" + zookeeperConfig + "' and query limit config: " + configuration); } + log.debug("Name: " + name); + if (this.configuration != null) { if (this.configuration.getDefaultUserQueryLimit() < 1) { throw new IllegalArgumentException("Default user query limit must be greater than 0"); @@ -201,6 +203,7 @@ public void countQueryTowardsLimits(String queryId, String userDn, String system boolean systemCountsTowardsUserLimits = systemLimitProvider.countsAgainstUserLimit(system); QueryHeartbeat heartbeat = getActiveQueryTracker().trackQuery(queryId, userDn, system, queryLogic, systemCountsTowardsUserLimits); + log.debug("heartbeatcache null? " + (heartbeatCache == null)); // Store the heartbeat into the cache. This acts as a means to keep the connection to Zookeeper alive for the ephemeral nodes stored in the heartbeat. heartbeatCache.put(heartbeat); } @@ -211,6 +214,7 @@ public void countQueryTowardsLimits(String queryId, String userDn, String system * @return the set of IDs for active queries */ public Set getActiveQueries() { + log.debug("heartbeatcache null? " + (heartbeatCache == null)); return heartbeatCache.getQueryIds(); } diff --git a/web-services/query/src/test/java/datawave/webservice/query/cache/QueryExpirationBeanTest.java b/web-services/query/src/test/java/datawave/webservice/query/cache/QueryExpirationBeanTest.java index 63d4485c6f9..624ed9e89d2 100644 --- a/web-services/query/src/test/java/datawave/webservice/query/cache/QueryExpirationBeanTest.java +++ b/web-services/query/src/test/java/datawave/webservice/query/cache/QueryExpirationBeanTest.java @@ -12,6 +12,7 @@ import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; +import org.springframework.test.util.ReflectionTestUtils; import datawave.core.common.connection.AccumuloConnectionFactory; import datawave.core.query.logic.QueryLogic; @@ -49,12 +50,12 @@ public void setUp() throws Exception { queryLimiter = Mockito.mock(QueryLimiter.class); this.bean = new QueryExpirationBean(); - bean.setQueryCache(queryCache); - bean.setQueryExpirationProperties(properties); - bean.setConnectionFactory(connectionFactory); - bean.setCreatedQueryLogicCacheBean(queryLogicCache); - bean.setQueryMetricsBean(metricsBean); - bean.setQueryLimiter(queryLimiter); + ReflectionTestUtils.setField(bean, "queryCache", queryCache); + ReflectionTestUtils.setField(bean, "config", properties); + ReflectionTestUtils.setField(bean, "connectionFactory", connectionFactory); + ReflectionTestUtils.setField(bean, "queryLogicCacheBean", queryLogicCache); + ReflectionTestUtils.setField(bean, "metricsBean", metricsBean); + ReflectionTestUtils.setField(bean, "queryLimiter", queryLimiter); bean.init(); } From b86b387e25580517582534919afca6bd3e274158 Mon Sep 17 00:00:00 2001 From: Laura Schanno Date: Wed, 6 May 2026 20:32:09 -0400 Subject: [PATCH 2/2] Remove debugging from QueryLimiter --- .../java/datawave/webservice/query/limit/QueryLimiter.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/web-services/query/src/main/java/datawave/webservice/query/limit/QueryLimiter.java b/web-services/query/src/main/java/datawave/webservice/query/limit/QueryLimiter.java index 8e1f3dff263..32c320029bd 100644 --- a/web-services/query/src/main/java/datawave/webservice/query/limit/QueryLimiter.java +++ b/web-services/query/src/main/java/datawave/webservice/query/limit/QueryLimiter.java @@ -91,8 +91,6 @@ public void setup() { log.debug("Initializing with zookeeperConfig: '" + zookeeperConfig + "' and query limit config: " + configuration); } - log.debug("Name: " + name); - if (this.configuration != null) { if (this.configuration.getDefaultUserQueryLimit() < 1) { throw new IllegalArgumentException("Default user query limit must be greater than 0"); @@ -203,7 +201,6 @@ public void countQueryTowardsLimits(String queryId, String userDn, String system boolean systemCountsTowardsUserLimits = systemLimitProvider.countsAgainstUserLimit(system); QueryHeartbeat heartbeat = getActiveQueryTracker().trackQuery(queryId, userDn, system, queryLogic, systemCountsTowardsUserLimits); - log.debug("heartbeatcache null? " + (heartbeatCache == null)); // Store the heartbeat into the cache. This acts as a means to keep the connection to Zookeeper alive for the ephemeral nodes stored in the heartbeat. heartbeatCache.put(heartbeat); } @@ -214,7 +211,6 @@ public void countQueryTowardsLimits(String queryId, String userDn, String system * @return the set of IDs for active queries */ public Set getActiveQueries() { - log.debug("heartbeatcache null? " + (heartbeatCache == null)); return heartbeatCache.getQueryIds(); }