Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.openjdk.jmh.annotations.Warmup;

import static java.util.concurrent.TimeUnit.SECONDS;
import static org.apache.ignite.internal.MessageSerializationContext.IGNORED;
import static org.openjdk.jmh.annotations.Mode.Throughput;

/** Benchmarks the {@link DirectMessageReader} compressed-field hot path. */
Expand Down Expand Up @@ -96,7 +97,7 @@ public void setup() {

writer.setBuffer(buf);

boolean finished = writer.writeMessage(msg, true);
boolean finished = writer.writeMessage(msg, true, IGNORED);

if (!finished)
throw new IllegalStateException("Message does not fit into the buffer.");
Expand All @@ -111,7 +112,7 @@ public Message compressedMessage() {

reader.setBuffer(buf);

Message msg = reader.readMessage(true);
Message msg = reader.readMessage(true, IGNORED);

reader.reset();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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.ignite.internal;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.apache.ignite.internal.processors.rollingupgrade.feature.IgniteFeature;

/**
* Links the annotated class to the specified {@link IgniteFeature} registry. The registry
* is used to resolve fully qualified names of features that introduced or deprecated fields
* declared by the annotated class (see {@link Order#introducedBy()} and {@link Order#deprecatedBy()}).
*
* <p>If this annotation is absent, the Ignite Core feature registry is used.</p>
*
* @see Order
* @see IgniteFeature
*/
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.TYPE)
public @interface FeatureRegistry {
/** @return Class of the associated feature registry. */
Class<?> value();
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@
import org.apache.ignite.internal.systemview.SystemViewRowAttributeWalkerProcessor;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.lang.IgniteBiTuple;
import org.jetbrains.annotations.Nullable;

import static org.apache.ignite.internal.MessageSerializerGenerator.DLFT_ENUM_MAPPER_CLS;
import static org.apache.ignite.internal.MessageSerializerGenerator.enumType;
import static org.apache.ignite.internal.MessageSerializerGenerator.resolveFeatureRegistry;

/**
* Annotation processor that generates serialization and deserialization code for classes implementing the {@code Message} interface.
Expand Down Expand Up @@ -105,6 +107,9 @@ public class MessageProcessor extends AbstractProcessor {
/** */
public static final Set<String> NO_PUBLIC_CTOR_MSGS = Set.of(GRID_H2_NULL, ZK_NO_SERVERS_MESSAGE);

/** */
private static final String IGNITE_FEATURE_CLS = "org.apache.ignite.internal.processors.rollingupgrade.feature.IgniteFeature";

/** Messages with no fields. A serializer generation intentionally skipped. */
static final String[] SKIP_MESSAGES = {
"org.apache.ignite.internal.processors.odbc.ClientMessage",
Expand Down Expand Up @@ -274,6 +279,7 @@ private List<List<VariableElement>> hierarchicalOrderedFields(TypeElement type)
}

validateEnumFieldMapping(type, el);
validateRollingUpgradeAnnotations(el);
}
}

Expand All @@ -282,6 +288,79 @@ private List<List<VariableElement>> hierarchicalOrderedFields(TypeElement type)
return hierList;
}

/** */
private void validateRollingUpgradeAnnotations(Element el) {
Order ann = el.getAnnotation(Order.class);

if (ann.introducedBy().isEmpty() && ann.deprecatedBy().isEmpty())
return;

String regCls = resolveFeatureRegistry(el.getEnclosingElement());

String introducedFeature = ann.introducedBy().isEmpty()
? null
: resolveFeatureFullName(el, ann.introducedBy(), regCls);

String deprecatedFeature = ann.deprecatedBy().isEmpty()
? null
: resolveFeatureFullName(el, ann.deprecatedBy(), regCls);

if (introducedFeature == null || deprecatedFeature == null)
return;

if (introducedFeature.equals(deprecatedFeature)) {
processingEnv.getMessager().printMessage(
Diagnostic.Kind.ERROR,
"Elements introducedBy and deprecatedBy of the @Order annotation must not reference the same feature.",
el);
}
}

/** */
@Nullable private String resolveFeatureFullName(Element el, String featureName, String regCls) {
TypeElement registryType = processingEnv.getElementUtils().getTypeElement(regCls);

if (registryType == null) {
processingEnv.getMessager().printMessage(
Diagnostic.Kind.ERROR, "Cannot resolve the feature registry class [registry=" + regCls + ']', el);

return null;
}

for (Element regTypeElement : registryType.getEnclosedElements()) {
if (regTypeElement.getKind() != ElementKind.FIELD || !regTypeElement.getSimpleName().contentEquals(featureName))
continue;

Set<Modifier> mods = regTypeElement.getModifiers();

if (!mods.contains(Modifier.PUBLIC) || !mods.contains(Modifier.STATIC) || !mods.contains(Modifier.FINAL)) {
processingEnv.getMessager().printMessage(
Diagnostic.Kind.ERROR,
"Feature constant must be public static final [registry=" + regCls + ", feature=" + featureName + ']', el);

return null;
}

TypeElement featureElement = processingEnv.getElementUtils().getTypeElement(IGNITE_FEATURE_CLS);

if (featureElement != null && !processingEnv.getTypeUtils().isAssignable(regTypeElement.asType(), featureElement.asType())) {
processingEnv.getMessager().printMessage(
Diagnostic.Kind.ERROR,
"Feature constant must be of type IgniteFeature [registry=" + regCls + ", feature=" + featureName + ']', el);

return null;
}

return regCls + '.' + featureName;
}

processingEnv.getMessager().printMessage(
Diagnostic.Kind.ERROR, "Failed to resolve feature in the registry by its name [featureName=" + featureName +
", registry=" + regCls + ']', el);

return null;
}

/**
* Validates consistency of enum field mappers configuration: the same mapper is used for the same enum across different messages,
* CustomMapper annotation is used only for enum fields.
Expand Down
Loading