Copilot commented on code in PR #17291: URL: https://github.com/apache/pinot/pull/17291#discussion_r2874643671
########## pinot-common/src/main/java/org/apache/pinot/common/systemtable/SystemTableRegistry.java: ########## @@ -0,0 +1,201 @@ +/** + * 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.common.systemtable; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.IdentityHashMap; +import java.util.Locale; +import java.util.Map; +import java.util.Set; +import javax.annotation.Nullable; +import org.apache.helix.HelixAdmin; +import org.apache.pinot.common.config.provider.TableCache; +import org.apache.pinot.spi.env.PinotConfiguration; +import org.apache.pinot.spi.utils.PinotReflectionUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * Registry to hold and lifecycle-manage system table data providers. + * <p> + * This class is thread-safe and manages the lifecycle of registered providers. + */ +public final class SystemTableRegistry implements AutoCloseable { + private static final Logger LOGGER = LoggerFactory.getLogger(SystemTableRegistry.class); + private static final String SYSTEM_TABLE_PREFIX = "system."; + + // Providers are registered once at broker startup. + private final Map<String, SystemTableProvider> _providers = new HashMap<>(); + private final SystemTableProviderContext _context; + private volatile boolean _closed = false; + + /** + * Creates a new SystemTableRegistry and initializes it with annotated providers. + */ + public SystemTableRegistry(TableCache tableCache, HelixAdmin helixAdmin, String clusterName, + @Nullable PinotConfiguration config) { + _context = new SystemTableProviderContext(tableCache, helixAdmin, clusterName, config); + registerAnnotatedProviders(); + } + + /** + * Registers a system table provider. + * <p> + * Note: This method does NOT call {@link SystemTableProvider#init(SystemTableProviderContext)} on the provider. + * It is intended for registering providers that have already been initialized (e.g. in tests). + * + * @throws IllegalArgumentException if the table name does not start with "system." + */ + public void register(SystemTableProvider provider) { + String tableName = provider.getTableName(); + if (!tableName.toLowerCase(Locale.ROOT).startsWith(SYSTEM_TABLE_PREFIX)) { + throw new IllegalArgumentException( + "System table name must start with '" + SYSTEM_TABLE_PREFIX + "', got: " + tableName); + } + synchronized (_providers) { + if (_closed) { + throw new IllegalStateException("Cannot register provider after registry is closed"); + } + _providers.put(normalize(tableName), provider); Review Comment: `SystemTableRegistry.register()` unconditionally overwrites any existing provider for the same normalized table name. That can mask duplicate providers and can leak resources because the displaced provider is never closed. Consider rejecting duplicates (throw) or closing/replacing explicitly with logging. ```suggestion String normalizedTableName = normalize(tableName); SystemTableProvider existingProvider = _providers.get(normalizedTableName); if (existingProvider != null && existingProvider != provider) { throw new IllegalStateException( "System table provider already registered for table '" + normalizedTableName + "'"); } _providers.put(normalizedTableName, provider); ``` ########## pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/admin/PinotTableAdminClient.java: ########## @@ -185,6 +185,23 @@ public List<String> cancelRebalance(String tableName) return _transport.parseStringArray(response, "jobIds"); } + /** + * Fetches the table size details. + * + * @param tableName Table name (raw or with type) + * @param verbose Whether to include per-segment details + * @param includeReplacedSegments Whether to include replaced segments + * @return Table size response as JsonNode + * @throws PinotAdminException If the request fails + */ + public JsonNode getTableSize(String tableName, boolean verbose, boolean includeReplacedSegments) + throws PinotAdminException { + Map<String, String> queryParams = new HashMap<>(); + queryParams.put("verbose", String.valueOf(verbose)); + queryParams.put("includeReplacedSegments", String.valueOf(includeReplacedSegments)); + return _transport.executeGet(_controllerAddress, "/tables/" + tableName + "/size", queryParams, _headers); + } Review Comment: `getTableSize()` builds the path with the raw `tableName` ("/tables/" + tableName + "/size") but does not URL-encode it. Other endpoints in this PR encode path segments to handle special characters safely; this one should do the same to avoid malformed requests for table names containing characters like spaces or '/'. -- 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]
