Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
77bc263
IGNITE-29220 Check the RFC process on pull requests
anton-vinogradov Nov 20, 2026
a5fa56f
Distinguish RFC objections from a technical veto on code
anton-vinogradov Nov 20, 2026
aaabf74
IGNITE-29326 Explain RFC findings in pull request comments
anton-vinogradov Nov 20, 2026
0003c7e
IGNITE-29326 Ignore comments without an author
anton-vinogradov Nov 20, 2026
16d2a7a
IGNITE-29326 Check public behavior changes against the published rules
anton-vinogradov Nov 20, 2026
4f95a9c
IGNITE-29326 Guide reviewers from an RFC draft to a verified vote
anton-vinogradov Nov 20, 2026
cf62522
IGNITE-29326 Group the public behavior check and name its review deci…
anton-vinogradov Nov 20, 2026
0017033
IGNITE-29326 Link to development processes from DEVNOTES
anton-vinogradov Nov 20, 2026
756333a
IGNITE-29326 Leave public behavior and vote decisions to reviewers
anton-vinogradov Nov 20, 2026
695fc6f
IGNITE-29326 Check RFC filenames and leave the text to reviewers
anton-vinogradov Nov 20, 2026
1363d41
IGNITE-29326 Identify public behavior review paths without labels
anton-vinogradov Nov 20, 2026
f281ef4
IGNITE-29326 Require an RFC for statically detected contract changes
anton-vinogradov Nov 20, 2026
b61d034
IGNITE-29326 Compare SQL error codes as integer values
anton-vinogradov Nov 20, 2026
389005c
IGNITE-29326 Check the RFC only after finding a public contract change
anton-vinogradov Nov 20, 2026
078ea94
IGNITE-29326 Require an RFC file in the PR for detected contract changes
anton-vinogradov Nov 20, 2026
3b70066
IGNITE-29326 Find RFCs in merged pull requests linked from the descri…
anton-vinogradov Nov 20, 2026
ced0174
IGNITE-29326 Accept direct links to existing RFC files in PR descript…
anton-vinogradov Nov 20, 2026
a241848
IGNITE-29326 Detect declared public behavior across Ignite interfaces…
anton-vinogradov Nov 20, 2026
25a5301
IGNITE-29326 Preserve equivalent Maven BOM declarations
anton-vinogradov Nov 20, 2026
d5ef5f4
IGNITE-29326 Check CLI subcommand arguments and system view column order
anton-vinogradov Nov 20, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
198 changes: 198 additions & 0 deletions .github/public-behavior/CliContracts.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
/*
* 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.
*/

import com.sun.source.tree.*;
import com.sun.source.util.TreeScanner;
import java.nio.file.Path;
import java.util.*;
import java.util.function.Consumer;
import javax.lang.model.element.Modifier;

class CliContracts {
static void compare(Path file, ClassTree before, ClassTree after, Consumer<String> output) {
// Moving declarations to another class may preserve the CLI.
if (before == null || after == null)
return;

String name = file.getFileName().toString();
if (name.equals("CommandHandler.java")) {
compareExitCodes(before, after, output);
return;
}

boolean commands = name.equals("IgniteCommandRegistry.java");
if (!commands && !name.equals("ArgumentParser.java"))
return;
Registrations old = registrations(before, commands);
Registrations now = registrations(after, commands);
if (old == null || now == null || !old.otherStatements().equals(now.otherStatements()))
return;
String label = commands ? "CLI command " : "CLI option ";
old.options().forEach((nameBefore, type) -> {
if (!now.options().containsKey(nameBefore))
output.accept("Removed " + label + nameBefore);
});
now.options().forEach((nameAfter, type) -> {
if (!old.options().containsKey(nameAfter))
output.accept("Added " + label + nameAfter);
else if (type != null && old.options().get(nameAfter) != null && !type.equals(old.options().get(nameAfter)))
output.accept("Changed CLI option " + nameAfter + " type from " + old.options().get(nameAfter) + " to " + type);
});
}

private record Registration(String name, String type) {}
private record Registrations(Map<String, String> options, List<String> otherStatements) {}

private static Registrations registrations(ClassTree cls, boolean commands) {
List<MethodTree> constructors = cls.getMembers().stream().filter(MethodTree.class::isInstance)
.map(MethodTree.class::cast).filter(m -> m.getReturnType() == null).toList();
if (constructors.size() != 1 || constructors.get(0).getBody() == null)
return null;
Map<String, Object> constants = constants(cls);
Map<String, String> options = new TreeMap<>();
List<String> other = new ArrayList<>();
boolean found = false;
for (StatementTree stmt : constructors.get(0).getBody().getStatements()) {
List<? extends ExpressionTree> args = null;
if (stmt instanceof ExpressionStatementTree expr && expr.getExpression() instanceof MethodInvocationTree call) {
if (commands && call.getMethodSelect().toString().equals("super"))
args = call.getArguments();
else if (!commands && call.getMethodSelect().toString().equals("common.addAll")
&& call.getArguments().size() == 1 && call.getArguments().get(0) instanceof MethodInvocationTree list
&& Set.of("List.of", "java.util.List.of").contains(list.getMethodSelect().toString()))
args = list.getArguments();
}
if (args == null) {
// A helper can register the same names that were removed from the list.
other.add(stmt.toString());
continue;
}
if (found)
return null;
found = true;
for (ExpressionTree arg : args) {
Registration registration = commands ? command(arg) : option(arg, constants);
if (registration == null)
return null;
options.put(registration.name(), registration.type());
}
}
return found ? new Registrations(options, other) : null;
}

private static Registration command(ExpressionTree arg) {
if (!(arg instanceof NewClassTree cmd) || cmd.getClassBody() != null)
return null;
String name = cmd.getIdentifier().toString();
name = name.substring(name.lastIndexOf('.') + 1);
if (!name.matches("[A-Z][a-zA-Z]*Command"))
return null;
// CommandUtils inserts a dash before each uppercase letter after the first one.
String stem = name.substring(0, name.length() - "Command".length());
return new Registration("--" + stem.replaceAll("(?<!^)([A-Z])", "-$1").toLowerCase(Locale.ROOT), null);
}

private static Registration option(ExpressionTree expr, Map<String, Object> constants) {
while (expr instanceof MethodInvocationTree call) {
String method = call.getMethodSelect().toString();
if (Set.of("argument", "optionalArgument").contains(method) && call.getArguments().size() == 2) {
ExpressionTree arg = call.getArguments().get(0);
Object name = arg instanceof LiteralTree lit ? lit.getValue() : constants.get(arg.toString());
if (!(name instanceof String option) || !option.matches("--[a-z0-9-]+"))
return null;
return new Registration(option, optionType(call.getArguments().get(1)));
}
if (!(call.getMethodSelect() instanceof MemberSelectTree chain))
break;
expr = chain.getExpression();
}
return null;
}

private static String optionType(ExpressionTree type) {
if (!(type instanceof MemberSelectTree selected) || !selected.getIdentifier().contentEquals("class"))
return null;
// CommandUtils parses primitive and boxed options alike. A password is read as one string.
String name = selected.getExpression().toString();
if (name.startsWith("java.lang."))
name = name.substring("java.lang.".length());
return switch (name) {
case "Boolean", "boolean" -> "boolean";
case "Integer", "int" -> "int";
case "Long", "long" -> "long";
case "Float", "float" -> "float";
case "Double", "double" -> "double";
case "String", "char[]" -> "string";
case "String[]" -> "string list";
default -> null;
};
}

private static Map<String, Object> constants(ClassTree cls) {
Map<String, Object> values = new HashMap<>();
for (Tree member : cls.getMembers()) {
if (member instanceof VariableTree field && field.getInitializer() instanceof LiteralTree literal
&& field.getModifiers().getFlags().containsAll(Set.of(Modifier.STATIC, Modifier.FINAL)))
values.put(field.getName().toString(), literal.getValue());
}
return values;
}

private static MethodTree execute(ClassTree cls) {
for (Tree member : cls.getMembers()) {
if (member instanceof MethodTree method && method.getName().contentEquals("execute")
&& "int".equals(String.valueOf(method.getReturnType())) && method.getParameters().size() == 1
&& Set.of("List<String>", "java.util.List<String>").contains(method.getParameters().get(0).getType().toString()))
return method;
}
return null;
}

private static void compareExitCodes(ClassTree before, ClassTree after, Consumer<String> output) {
MethodTree old = execute(before);
MethodTree now = execute(after);
// If the dispatch changed, a different return statement may still give callers the same code.
if (old == null || now == null || old.getBody() == null || now.getBody() == null
|| !old.getBody().toString().equals(now.getBody().toString()))
return;
Set<String> returned = new TreeSet<>();
Set<String> locals = new HashSet<>();
new TreeScanner<Void, Void>() {
@Override public Void visitVariable(VariableTree var, Void p) {
locals.add(var.getName().toString());
return super.visitVariable(var, p);
}

@Override public Void visitReturn(ReturnTree ret, Void p) {
if (ret.getExpression() instanceof IdentifierTree id)
returned.add(id.getName().toString());
return null;
}

@Override public Void visitLambdaExpression(LambdaExpressionTree lambda, Void p) { return null; }
@Override public Void visitClass(ClassTree nested, Void p) { return null; }
}.scan(old.getBody(), null);
returned.removeAll(locals);
Map<String, Object> oldValues = constants(before);
Map<String, Object> newValues = constants(after);
for (String status : returned) {
if (oldValues.get(status) instanceof Integer from && newValues.get(status) instanceof Integer to
&& !from.equals(to))
output.accept("Changed CLI exit code for " + status + " from " + from + " to " + to);
}
}
}
113 changes: 113 additions & 0 deletions .github/public-behavior/ErrorMapping.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
* 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.
*/

import com.sun.source.tree.*;
import java.nio.file.Path;
import java.util.*;
import java.util.function.BiConsumer;
import javax.lang.model.element.Modifier;

/** SQLState returned for a numeric Ignite error by the JDBC error mapping. */
class ErrorMapping {
private static final Path ROOT = Path.of("modules/core/src/main/java/org/apache/ignite/internal/processors");
private static final Path ERRORS = ROOT.resolve("cache/query/IgniteQueryErrorCode.java");
private static final Path STATES = ROOT.resolve("odbc/SqlStateCode.java");

static void compare(Map<Path, ClassTree> before, Map<Path, ClassTree> after, BiConsumer<Path, String> output) {
Map<Integer, String> old = mapping(before);
for (var entry : mapping(after).entrySet()) {
String from = old.get(entry.getKey());
if (from != null && !from.equals(entry.getValue()))
output.accept(ERRORS, "Changed SQLState for error " + entry.getKey() + " from " + from + " to " + entry.getValue());
}
}

private static Map<Integer, String> mapping(Map<Path, ClassTree> types) {
ClassTree errors = types.get(ERRORS);
ClassTree states = types.get(STATES);
if (errors == null || states == null)
return Map.of();
Map<String, String> values = new HashMap<>();
for (Tree member : states.getMembers()) {
if (member instanceof VariableTree field && JavaContracts.literal(field.getInitializer()) instanceof String value)
values.put(field.getName().toString(), value);
}
Map<String, Integer> codes = new HashMap<>();
for (Tree member : errors.getMembers()) {
if (member instanceof VariableTree field && field.getType().toString().equals("int")
&& field.getModifiers().getFlags().containsAll(Set.of(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL))
&& JavaContracts.literal(field.getInitializer()) instanceof Integer value)
codes.put(field.getName().toString(), value);
}
for (Tree member : errors.getMembers()) {
if (member instanceof MethodTree method && method.getName().contentEquals("codeToSqlState")
&& method.getParameters().size() == 1 && method.getParameters().get(0).getType().toString().equals("int")
&& method.getBody() != null && method.getBody().getStatements().size() == 1
&& method.getBody().getStatements().get(0) instanceof SwitchTree sw) {
ExpressionTree selector = sw.getExpression();
while (selector instanceof ParenthesizedTree parens)
selector = parens.getExpression();
if (selector instanceof IdentifierTree id && id.getName().equals(method.getParameters().get(0).getName()))
return switchValues(sw, codes, values);
}
}
return Map.of();
}

private static Map<Integer, String> switchValues(SwitchTree sw, Map<String, Integer> codes, Map<String, String> states) {
Map<Integer, String> result = new TreeMap<>();
List<Integer> pending = new ArrayList<>();
boolean defaultFallsThrough = false;
String fallback = null;
for (CaseTree branch : sw.getCases()) {
if (branch.getCaseKind() != CaseTree.CaseKind.STATEMENT)
return Map.of();
if (branch.getExpressions().isEmpty())
defaultFallsThrough = true;
for (ExpressionTree key : branch.getExpressions()) {
if (!(key instanceof IdentifierTree id) || !codes.containsKey(id.getName().toString()))
return Map.of();
pending.add(codes.get(id.getName().toString()));
}
var statements = branch.getStatements();
if (statements.isEmpty())
continue;
if (statements.size() != 1 || !(statements.get(0) instanceof ReturnTree ret))
return Map.of();
ExpressionTree expr = ret.getExpression();
String state = null;
if (JavaContracts.literal(expr) instanceof String literal)
state = literal;
else if (expr instanceof MemberSelectTree ref && ref.getExpression().toString().equals("SqlStateCode"))
state = states.get(ref.getIdentifier().toString());
if (state == null)
return Map.of();
for (Integer code : pending)
result.put(code, state);
if (defaultFallsThrough) {
fallback = state;
defaultFallsThrough = false;
}
pending.clear();
}
if (fallback != null) {
for (Integer code : codes.values())
result.putIfAbsent(code, fallback);
}
return result;
}
}
Loading
Loading