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 @@ -22,6 +22,7 @@
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.internal.CoreMessagesProvider;
import org.apache.ignite.internal.benchmarks.jmh.runner.JmhIdeBenchmarkRunner;
import org.apache.ignite.internal.direct.DirectMessageReader;
Expand All @@ -30,6 +31,8 @@
import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage;
import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GroupPartitionIdPair;
import org.apache.ignite.internal.processors.cache.persistence.wal.reader.StandaloneGridKernalContext;
import org.apache.ignite.logger.NullLogger;
import org.apache.ignite.plugin.extensions.communication.Message;
import org.apache.ignite.plugin.extensions.communication.MessageFactory;
import org.apache.ignite.plugin.extensions.communication.MessageFactoryProvider;
Expand Down Expand Up @@ -73,7 +76,7 @@ public static void main(String[] args) throws Exception {

/** */
@Setup
public void setup() {
public void setup() throws IgniteCheckedException {
MessageFactory msgFactory = msgFactory();

reader = new DirectMessageReader(msgFactory, null);
Expand Down Expand Up @@ -120,8 +123,8 @@ public Message compressedMessage() {
}

/** */
private static MessageFactory msgFactory() {
return new IgniteMessageFactoryImpl(new MessageFactoryProvider[]{
new CoreMessagesProvider()});
private static MessageFactory msgFactory() throws IgniteCheckedException {
return new IgniteMessageFactoryImpl(new MessageFactoryProvider[] {
new CoreMessagesProvider(new StandaloneGridKernalContext(new NullLogger(), null))});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,14 @@ public class MessageProcessor extends AbstractProcessor {
/** */
public static final Set<String> NO_PUBLIC_CTOR_MSGS = Set.of(GRID_H2_NULL, ZK_NO_SERVERS_MESSAGE);

/** Messages with no fields. A serializer generation intentionally skipped. */
/** */
static final String OP_CTX_SNAPSHOT_MESSAGE_CLASS = "org.apache.ignite.internal.thread.context.OperationContextSnapshotMessage";

/** Messages with no fields, or with a hand-written serializer. A serializer generation intentionally skipped. */
static final String[] SKIP_MESSAGES = {
"org.apache.ignite.internal.processors.odbc.ClientMessage",
COMPRESSED_MESSAGE_CLASS,
OP_CTX_SNAPSHOT_MESSAGE_CLASS,
"org.apache.ignite.loadtests.communication.GridTestMessage",
"org.apache.ignite.spi.communication.tcp.TestDelayMessage"
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@
import org.apache.ignite.internal.processors.service.ServiceTopology;
import org.apache.ignite.internal.processors.service.ServiceUndeploymentRequest;
import org.apache.ignite.internal.thread.context.OperationContextSnapshotMessage;
import org.apache.ignite.internal.thread.context.OperationContextSnapshotMessageSerializer;
import org.apache.ignite.internal.util.ErrorMessage;
import org.apache.ignite.internal.util.GridByteArrayList;
import org.apache.ignite.internal.util.GridIntList;
Expand All @@ -291,6 +292,7 @@
import org.apache.ignite.internal.util.distributed.InitMessage;
import org.apache.ignite.internal.util.distributed.SingleNodeMessage;
import org.apache.ignite.plugin.extensions.communication.Message;
import org.apache.ignite.plugin.extensions.communication.MessageSerializer;
import org.apache.ignite.plugin.security.SecurityBasicPermissionSet;
import org.apache.ignite.spi.collision.jobstealing.JobStealingRequest;
import org.apache.ignite.spi.communication.tcp.internal.TcpConnectionRequestDiscoveryMessage;
Expand Down Expand Up @@ -351,12 +353,12 @@ public class CoreMessagesProvider extends AbstractMessageFactoryProvider {
/** */
private @Nullable IgniteMessageFactory factory;

/**
* Default plugin-purposes constructor.
*
*/
public CoreMessagesProvider() {
// No-op.
/** */
private final GridKernalContext ctx;

/** */
public CoreMessagesProvider(GridKernalContext ctx) {
this.ctx = ctx;
}

/**
Expand Down Expand Up @@ -751,7 +753,7 @@ public CoreMessagesProvider() {

// [13400 - 13500]: Operation context messages.
msgIdx = 13400;
register(OperationContextSnapshotMessage.class);
register(OperationContextSnapshotMessage.class, new OperationContextSnapshotMessageSerializer(ctx));
register(SecurityContextWrapper.class);

// [13600 - 13700]: Rolling Upgrade messages.
Expand All @@ -769,4 +771,9 @@ public CoreMessagesProvider() {
private <T extends Message> void register(Class<T> cls) {
register(factory, cls, msgIdx++);
}

/** */
private <T extends Message> void register(Class<T> cls, MessageSerializer<T> serializer) {
register(factory, cls, msgIdx++, serializer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,7 @@ private void initMessageFactory() throws IgniteCheckedException {

List<MessageFactoryProvider> compMsgs = new ArrayList<>();

compMsgs.add(new CoreMessagesProvider());
compMsgs.add(new CoreMessagesProvider(ctx));

for (IgniteComponentType compType : IgniteComponentType.values()) {
MessageFactoryProvider f = compType.messageFactory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ public abstract class AbstractMessageFactoryProvider implements MessageFactoryPr

/** Register a message with a caller-provided {@code id}. */
protected <T extends Message> void register(IgniteMessageFactory factory, Class<T> cls, short id) {
MessageSerializer<T> serializer = loadGenerated(cls, "Serializer", true);
register(factory, cls, id, loadGenerated(cls, "Serializer", true));
}

/** */
protected <T extends Message> void register(IgniteMessageFactory factory, Class<T> cls, short id, MessageSerializer<T> serializer) {
// A message that marshals a part of its fields itself always gets a generated marshaller (its own call alone
// is a statement), so its absence is a build problem. For the rest the generator skips statement-free
// marshallers, so absence legitimately means "nothing to marshal"; the message and its companions ship in the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,15 @@ public class CoreFeatureRegistry {

/** Feature that deprecates {@code GridDhtTxFinishRequest#nearNodeId}. */
public static final IgniteFeature DHT_TX_FINISH_NEAR_NODE_ID_DEPRECATED_FEATURE = new IgniteCoreFeature(8);

/**
* Feature that makes distributed operation context attributes Rolling Upgrade-compatible. It introduces:
*
* <ul>
* <li>The ability to specify the feature that introduced a distributed attribute.</li>
* <li>Delivery of a distributed attribute through nodes that do not know it to the nodes that do.</li>
* <li>A more compact serialized form of the operation context snapshot.</li>
* </ul>
*/
public static final IgniteFeature RU_AWARE_DISTRIBUTED_OP_CTX_FEATURE = new IgniteCoreFeature(9);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@

package org.apache.ignite.internal.thread.context;

import org.apache.ignite.internal.processors.rollingupgrade.feature.IgniteFeature;
import org.apache.ignite.internal.util.tostring.GridToStringInclude;
import org.apache.ignite.internal.util.typedef.internal.S;
import org.jetbrains.annotations.Nullable;

import static org.apache.ignite.internal.thread.context.OperationContextSnapshotMessage.MAX_ATTRS_CNT;

Expand All @@ -36,18 +38,33 @@ public final class DistributedAttributeKey {
@GridToStringInclude
private final byte id;

/** */
@GridToStringInclude
@Nullable private final IgniteFeature introducedBy;

/** */
DistributedAttributeKey(int id) {
this(id, null);
}

/** */
DistributedAttributeKey(int id, @Nullable IgniteFeature introducedBy) {
assert 0 <= id && id < MAX_ATTRS_CNT : "Invalid distributed attribute id [id=" + id + ']';

this.id = (byte)id;
this.introducedBy = introducedBy;
}

/** @return Cluster-wide id of the attribute. */
public byte id() {
return id;
}

/** @return Feature that introduced the attribute, or {@code null} if every peer reads it. */
public @Nullable IgniteFeature introducedBy() {
return introducedBy;
}

/** {@inheritDoc} */
@Override public boolean equals(Object o) {
if (this == o)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
package org.apache.ignite.internal.thread.context;

import java.util.Arrays;
import java.util.List;
import org.apache.ignite.IgniteException;
import org.apache.ignite.plugin.extensions.communication.Message;
import org.apache.ignite.plugin.extensions.communication.RawField;
import org.jetbrains.annotations.Nullable;

import static org.apache.ignite.internal.thread.context.OperationContextSnapshotMessage.nextAttributeId;
Expand All @@ -45,6 +47,9 @@
* @see OperationContextSnapshotMessage
*/
public class DistributedOperationContext {
/** */
private static final OperationContextAttribute<List<RawField>> RAW_VALS_HOLDER_ATTR = OperationContextAttribute.newInstance();

/** Registered distributed attributes by their cluster-wide id. */
private volatile DistributedAttribute[] distrAttrs = new DistributedAttribute[0];

Expand Down Expand Up @@ -123,10 +128,16 @@ public synchronized <T extends Message> void register(DistributedAttributeKey ke
idBitmap = set(idBitmap, id);
}

if (attrs == null)
List<RawField> rawAttrs = OperationContext.get(RAW_VALS_HOLDER_ATTR);

if (attrs == null && rawAttrs == null)
return null;

return new OperationContextSnapshotMessage(idBitmap, cnt == attrs.length ? attrs : Arrays.copyOf(attrs, cnt));
OperationContextSnapshotMessage snp = new OperationContextSnapshotMessage(idBitmap, shrink(attrs, cnt));

snp.rawFields(rawAttrs);

return snp;
}

/** Restores {@link OperationContextAttribute} values received from a remote node. */
Expand All @@ -145,9 +156,20 @@ public Scope restoreSnapshot(@Nullable OperationContextSnapshotMessage snp) {
ctxRestorer.add((OperationContextAttribute<Message>)locDistrAttrs[attrId].attr, snp.getValue(attrId));
}

if (snp.rawFields() != null)
ctxRestorer.add(RAW_VALS_HOLDER_ATTR, snp.rawFields());

return ctxRestorer.restore();
}

/** */
private static Message[] shrink(@Nullable Message[] attrs, int cnt) {
if (attrs == null)
return new Message[0];

return cnt == attrs.length ? attrs : Arrays.copyOf(attrs, cnt);
}

/** Restricts further registration of distributed attributes. */
public synchronized void finishRegistration() {
regFinished = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package org.apache.ignite.internal.thread.context;

import org.apache.ignite.internal.Order;
import java.util.Arrays;
import org.apache.ignite.plugin.extensions.communication.AbstractMessage;
import org.apache.ignite.plugin.extensions.communication.Message;

Expand All @@ -30,14 +30,12 @@ public class OperationContextSnapshotMessage extends AbstractMessage {
/** Maximal number of supported distributed attributes. */
static final int MAX_ATTRS_CNT = Byte.SIZE;

/** Values of operation context attributes, in ascending id order. */
@Order(0)
Message[] attrs;

/** Bitmap of attributes ids. */
@Order(1)
byte idBitmap;

/** Values of operation context attributes, in ascending id order. */
Message[] attrs;

/** Empty constructor for serialization purposes. */
public OperationContextSnapshotMessage() {
// No-op.
Expand All @@ -58,6 +56,22 @@ Message getValue(int attrId) {
return attrs[valueIndex(attrId)];
}

/** */
void setValue(int attrId, Message val) {
assert !contains(idBitmap, attrId);

int valIdx = valueIndex(attrId);

Message[] res = Arrays.copyOf(attrs, attrs.length + 1);

System.arraycopy(attrs, valIdx, res, valIdx + 1, attrs.length - valIdx);

res[valIdx] = val;

attrs = res;
idBitmap = set(idBitmap, attrId);
}

/** */
private int valueIndex(int attrId) {
return Integer.bitCount(idBitmap & ((1 << attrId) - 1));
Expand Down
Loading
Loading