somandal commented on code in PR #17159:
URL: https://github.com/apache/pinot/pull/17159#discussion_r2501079901
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/ServerReloadJobStatusCache.java:
##########
@@ -92,4 +106,81 @@ public ReloadJobStatus getOrCreate(String jobId) {
}
return status;
}
+
+ /**
+ * Rebuilds the cache with new configuration and migrates existing entries.
+ * This method is synchronized to prevent concurrent rebuilds.
+ *
+ * @param newConfig new cache configuration to apply
+ */
+ private synchronized void rebuildCache(ServerReloadJobStatusCacheConfig
newConfig) {
+ LOG.info("Rebuilding reload status cache with new config: {}", newConfig);
+
+ // Create new cache with new configuration
+ Cache<String, ReloadJobStatus> newCache = CacheBuilder.newBuilder()
+ .maximumSize(newConfig.getMaxSize())
+ .expireAfterWrite(newConfig.getTtlDays(), TimeUnit.DAYS)
+ .recordStats()
+ .build();
+
+ // Migrate existing entries from old cache to new cache
+ Cache<String, ReloadJobStatus> oldCache = _cache;
+ if (oldCache != null) {
+ for (Map.Entry<String, ReloadJobStatus> entry :
oldCache.asMap().entrySet()) {
+ newCache.put(entry.getKey(), entry.getValue());
+ }
+ }
+
+ // Atomically swap caches (volatile field ensures safe publication)
+ _cache = newCache;
+ _currentConfig = newConfig;
+
+ LOG.info("Successfully rebuilt reload status cache (size: {})",
newCache.size());
+ }
+
+ /**
+ * Maps cluster configuration properties with a common prefix to a config
POJO using Jackson.
+ * Uses PinotConfiguration.subset() to extract properties with the given
prefix and
+ * Jackson's convertValue() for automatic object mapping.
+ *
+ * @param clusterConfigs map of all cluster configs from ZooKeeper
+ * @param configPrefix prefix to filter configs (e.g.,
"pinot.server.table.reload.status.cache")
+ * @return ServerReloadJobStatusCacheConfig with values from cluster config,
defaults for missing values
+ */
+ @VisibleForTesting
+ static ServerReloadJobStatusCacheConfig buildFromClusterConfig(Map<String,
String> clusterConfigs,
+ String configPrefix) {
+ final MapConfiguration mapConfig = new MapConfiguration(clusterConfigs);
+ final PinotConfiguration subsetConfig = new
PinotConfiguration(mapConfig).subset(configPrefix);
+ return OBJECT_MAPPER.convertValue(subsetConfig.toMap(),
ServerReloadJobStatusCacheConfig.class);
+ }
+
+ /**
+ * Gets the current cache configuration.
+ * Useful for testing and monitoring.
Review Comment:
i see this comment ("Useful for testing and monitoring.") pop up once in a
while and it never makes sense IMO to have this as a comment in the code. can
we proactively remove them going forward?
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/ServerReloadJobStatusCache.java:
##########
@@ -35,26 +42,33 @@
*
* <p>Thread-safe for concurrent access. Uses Guava Cache with LRU eviction
* and time-based expiration.
+ *
+ * <p>Implements PinotClusterConfigChangeListener to support dynamic
configuration
+ * updates from ZooKeeper cluster config. When config changes, cache is rebuilt
+ * with new settings and existing entries are migrated.
*/
@ThreadSafe
-public class ServerReloadJobStatusCache {
+public class ServerReloadJobStatusCache implements
PinotClusterConfigChangeListener {
private static final Logger LOG =
LoggerFactory.getLogger(ServerReloadJobStatusCache.class);
+ private static final String CONFIG_PREFIX =
"pinot.server.table.reload.status.cache";
+ private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
- private final Cache<String, ReloadJobStatus> _cache;
+ private volatile Cache<String, ReloadJobStatus> _cache;
+ private ServerReloadJobStatusCacheConfig _currentConfig;
/**
- * Creates a cache with the given configuration.
- *
+ * Creates a cache with default configuration.
Review Comment:
should we overridable defaults which aren't hard coded but taken from the
config instead for initialization purposes? This allows configuring these
values without always relying on the cluster config way. I know some folks who
rely on code use the standard configurations (via conf file) and don't use
cluster configs. we should always aim to support both mechanisms
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/ServerReloadJobStatusCache.java:
##########
@@ -35,26 +42,33 @@
*
* <p>Thread-safe for concurrent access. Uses Guava Cache with LRU eviction
* and time-based expiration.
+ *
+ * <p>Implements PinotClusterConfigChangeListener to support dynamic
configuration
+ * updates from ZooKeeper cluster config. When config changes, cache is rebuilt
+ * with new settings and existing entries are migrated.
*/
@ThreadSafe
-public class ServerReloadJobStatusCache {
+public class ServerReloadJobStatusCache implements
PinotClusterConfigChangeListener {
private static final Logger LOG =
LoggerFactory.getLogger(ServerReloadJobStatusCache.class);
+ private static final String CONFIG_PREFIX =
"pinot.server.table.reload.status.cache";
+ private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
- private final Cache<String, ReloadJobStatus> _cache;
+ private volatile Cache<String, ReloadJobStatus> _cache;
+ private ServerReloadJobStatusCacheConfig _currentConfig;
Review Comment:
would it make sense to make this volatile too?
##########
pinot-segment-local/src/test/java/org/apache/pinot/segment/local/utils/ServerReloadJobStatusCacheTest.java:
##########
@@ -0,0 +1,363 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.segment.local.utils;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.testng.annotations.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+
+/**
+ * Unit tests for ServerReloadJobStatusCache to verify correct config injection
+ * when onChange is called, cache rebuild logic, and entry migration.
+ */
+public class ServerReloadJobStatusCacheTest {
+
+ private static final String CONFIG_PREFIX =
"pinot.server.table.reload.status.cache";
Review Comment:
nit: can we get this from the common constants / class where it is defined?
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/ServerReloadJobStatusCacheConfig.java:
##########
@@ -18,12 +18,20 @@
*/
package org.apache.pinot.segment.local.utils;
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
/**
* Configuration for ReloadJobStatusCache.
+ * Uses Jackson annotations for automatic JSON mapping from
ClusterConfiguration.
*/
+@JsonIgnoreProperties(ignoreUnknown = true)
public class ServerReloadJobStatusCacheConfig {
+ @JsonProperty("size.max")
Review Comment:
nit: consider making config name and variable name consistent (both max.size
or size.max)
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/ServerReloadJobStatusCache.java:
##########
@@ -35,26 +42,33 @@
*
* <p>Thread-safe for concurrent access. Uses Guava Cache with LRU eviction
* and time-based expiration.
+ *
+ * <p>Implements PinotClusterConfigChangeListener to support dynamic
configuration
+ * updates from ZooKeeper cluster config. When config changes, cache is rebuilt
+ * with new settings and existing entries are migrated.
*/
@ThreadSafe
-public class ServerReloadJobStatusCache {
+public class ServerReloadJobStatusCache implements
PinotClusterConfigChangeListener {
private static final Logger LOG =
LoggerFactory.getLogger(ServerReloadJobStatusCache.class);
+ private static final String CONFIG_PREFIX =
"pinot.server.table.reload.status.cache";
Review Comment:
we usually put these kinds of things in `CommonConstants`, consider moving
it there
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]