xiangfu0 commented on code in PR #18411:
URL: https://github.com/apache/pinot/pull/18411#discussion_r3185144683
##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotTableRestletResource.java:
##########
@@ -346,6 +350,11 @@ public CopyTableResponse copyTable(
ObjectNode realtimeTableConfigNode = (ObjectNode)
tableConfigNode.get(TableType.REALTIME.name());
tweakRealtimeTableConfig(realtimeTableConfigNode, copyTablePayload);
+ try {
+
DeprecatedTableConfigValidationUtils.validateNoDeprecatedConfigs(realtimeTableConfigNode);
+ } catch (IllegalStateException e) {
Review Comment:
Good catch — fixed in 19423f1e20. `copyTable` now catches
`IllegalArgumentException` so the deprecated-config rejection stays at 400
(BAD_REQUEST) instead of falling through to the generic 500 handler.
##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/DeprecatedTableConfigValidationUtils.java:
##########
@@ -0,0 +1,445 @@
+/**
+ * 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.controller.api.resources;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.JsonNode;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import javax.annotation.Nullable;
+import org.apache.pinot.common.version.PinotVersion;
+import org.apache.pinot.spi.config.BaseJsonConfig;
+import org.apache.pinot.spi.config.DeprecatedConfig;
+import org.apache.pinot.spi.config.table.TableConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Validates raw table-config JSON for deprecated properties on create and
update paths.
+ *
+ * <p>Rules are derived at class-load time from {@link DeprecatedConfig}
annotations on getters reachable from
+ * {@link TableConfig}. A violation's severity ({@link Severity#WARNING} vs
{@link Severity#ERROR}) is decided by
+ * comparing the annotation's {@code since} version against the running Pinot
version (see
+ * {@link #classifySeverity}): properties deprecated in the current
major.minor release are warnings; properties
+ * deprecated in any earlier release are errors. When the running version
cannot be determined, all violations are
+ * reported as errors so the safe default is to reject.
+ *
+ * <p>The validator operates on raw JSON rather than the deserialized {@link
TableConfig} so it can detect
+ * explicitly provided deprecated keys even when they carry default or false-y
values that Jackson would otherwise
+ * elide.</p>
+ */
+public final class DeprecatedTableConfigValidationUtils {
+ private DeprecatedTableConfigValidationUtils() {
+ }
+
+ private static final Logger LOGGER =
LoggerFactory.getLogger(DeprecatedTableConfigValidationUtils.class);
+ private static final String WILDCARD = "*";
+ // CURRENT_MAJOR_MINOR must be initialized before RULES because
discoverRules() -> classifySeverity() reads it.
+ private static final String CURRENT_MAJOR_MINOR = currentMajorMinor();
+ private static final List<DeprecatedConfigRule> RULES = discoverRules();
+
+ public enum Severity {
+ WARNING, ERROR
+ }
+
+ /**
+ * Result of validating a table-config JSON, exposing errors and warnings
separately so callers can decide whether
+ * to reject the request or surface non-fatal warnings to the user.
+ */
+ public static final class Result {
+ private final List<String> _errors;
+ private final List<String> _warnings;
+
+ private Result(List<String> errors, List<String> warnings) {
+ _errors = List.copyOf(errors);
+ _warnings = List.copyOf(warnings);
+ }
+
+ public List<String> getErrors() {
+ return _errors;
+ }
+
+ public List<String> getWarnings() {
+ return _warnings;
+ }
+
+ public boolean hasErrors() {
+ return !_errors.isEmpty();
+ }
+
+ public boolean hasWarnings() {
+ return !_warnings.isEmpty();
+ }
+ }
+
+ /**
+ * Validates a table-config JSON document. When {@code oldTableConfigJson}
is non-null, only paths whose value
+ * newly appears in {@code newTableConfigJson} or whose value differs from
the corresponding path in
+ * {@code oldTableConfigJson} are reported, so re-submitting an unchanged
legacy field on an update is a no-op.
+ * When {@code oldTableConfigJson} is null (creation path), every present
deprecated path is reported.
+ *
+ * @param newTableConfigJson the incoming table config to validate; must not
be {@code null}
+ * @param oldTableConfigJson the currently-stored table config to diff
against, or {@code null} for create paths
+ * @param rootPathPrefix optional prefix for emitted paths (e.g. {@code
"realtime"} when validating a sub-section)
+ */
+ public static Result validate(JsonNode newTableConfigJson, @Nullable
JsonNode oldTableConfigJson,
+ @Nullable String rootPathPrefix) {
+ Objects.requireNonNull(newTableConfigJson, "newTableConfigJson");
+ List<String> errors = new ArrayList<>();
+ List<String> warnings = new ArrayList<>();
+ String prefix = rootPathPrefix == null ? "" : rootPathPrefix;
+ for (DeprecatedConfigRule rule : RULES) {
+ rule.collect(newTableConfigJson, oldTableConfigJson, prefix, errors,
warnings);
+ }
+ return new Result(errors, warnings);
+ }
+
+ /**
+ * Validates a freshly-submitted table config (no prior stored value). On
any error the method throws
+ * {@link IllegalStateException}; warnings are returned so the caller can
surface them in the response.
+ */
+ public static List<String> validateOnCreate(JsonNode newTableConfigJson,
@Nullable String rootPathPrefix) {
+ Result result = validate(newTableConfigJson, null, rootPathPrefix);
+ if (result.hasErrors()) {
+ throw new IllegalArgumentException("Deprecated table config properties
are not allowed on table creation: "
+ + String.join("; ", result.getErrors()));
+ }
Review Comment:
Fixed in 19423f1e20. Updated the Javadoc on both `validateOnCreate` and
`validateOnUpdate` to say `IllegalArgumentException`, matching the actual
thrown type. `copyTable` was the one in-tree caller that catches the exception
by type and was updated in the same commit.
--
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]