cmccabe commented on code in PR #12036:
URL: https://github.com/apache/kafka/pull/12036#discussion_r848895075
##########
clients/src/main/java/org/apache/kafka/clients/admin/FeatureUpdate.java:
##########
@@ -23,33 +23,92 @@
*/
public class FeatureUpdate {
private final short maxVersionLevel;
- private final boolean allowDowngrade;
+ private final DowngradeType downgradeType;
+
+ public enum DowngradeType {
+ NONE(0),
+ SAFE(1),
+ UNSAFE(2);
+
+ private final byte code;
+
+ DowngradeType(int code) {
+ this.code = (byte) code;
+ }
+
+ public byte code() {
+ return code;
+ }
+
+ public static DowngradeType fromCode(int code) {
+ if (code == 0) {
+ return NONE;
+ } else if (code == 1) {
+ return SAFE;
+ } else if (code == 2) {
+ return UNSAFE;
+ } else {
+ throw new IllegalArgumentException("No downgrade type for code
" + code);
+ }
+ }
+ }
/**
* @param maxVersionLevel the new maximum version level for the
finalized feature.
* a value < 1 is special and indicates that
the update is intended to
* delete the finalized feature, and should be
accompanied by setting
* the allowDowngrade flag to true.
* @param allowDowngrade - true, if this feature update was meant to
downgrade the existing
- * maximum version level of the finalized
feature.
+ * maximum version level of the finalized
feature. Only "safe" downgrades are
+ * enabled with this boolean. See {@link
FeatureUpdate#FeatureUpdate(short, DowngradeType)}
* - false, otherwise.
*/
+ @Deprecated
public FeatureUpdate(final short maxVersionLevel, final boolean
allowDowngrade) {
if (maxVersionLevel < 1 && !allowDowngrade) {
throw new IllegalArgumentException(String.format(
"The allowDowngrade flag should be set when the provided
maxVersionLevel:%d is < 1.",
maxVersionLevel));
}
this.maxVersionLevel = maxVersionLevel;
- this.allowDowngrade = allowDowngrade;
+ if (allowDowngrade) {
+ this.downgradeType = DowngradeType.SAFE;
+ } else {
+ this.downgradeType = DowngradeType.NONE;
+ }
+ }
+
+ /**
+ * @param maxVersionLevel The new maximum version level for the
finalized feature.
+ * a value < 1 is special and indicates that
the update is intended to
+ * delete the finalized feature, and should be
accompanied by setting
+ * the allowDowngrade flag to true.
+ * @param downgradeType Indicate what kind of downgrade, if any, is
allowed in this operation.
+ * - NONE: no downgrades are permitted
+ * - SAFE: only downgrades which do not lose
metadata are permitted
+ * - UNSAFE: any downgrade, including those which
may result in metadata loss, are permitted
+ */
+ public FeatureUpdate(final short maxVersionLevel, final DowngradeType
downgradeType) {
+ if (maxVersionLevel < 1 && downgradeType.equals(DowngradeType.NONE)) {
Review Comment:
Can we just throw an exception if someone gives a negative number? It would
be good to just disallow this from day one since it's not meaningful.
--
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]