-
Notifications
You must be signed in to change notification settings - Fork 1.9k
IGNITE-28770 : Introduce a operation context attributes registry v2 #13243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Vladsz83
wants to merge
21
commits into
apache:master
Choose a base branch
from
Vladsz83:IGNITE-28770-Introduce-a-operation-context-attributes-registry_v2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
1740273
impl
Vladsz83 77910fa
Merge branch 'master' into IGNITE-28770-Introduce-a-operation-context…
Vladsz83 baa1473
in-progress
Vladsz83 9f8e09d
raw
Vladsz83 72b5c17
Merge branch 'master' into IGNITE-28770-Introduce-a-operation-context…
Vladsz83 9f4ccec
impl
Vladsz83 c73b97c
Merge branch 'master' into IGNITE-28770-Introduce-a-operation-context…
Vladsz83 1987030
review fixes
Vladsz83 d293eb0
fix
Vladsz83 1395caf
review fixes
Vladsz83 79dab0b
reimpol
Vladsz83 695f18d
review fixes
Vladsz83 f0d579f
review fixes
Vladsz83 13d5f11
renaming
Vladsz83 61ef963
Merge branch 'master' into IGNITE-28770-Introduce-a-operation-context…
Vladsz83 1bc5fa8
review fixes
Vladsz83 cb024d1
fix
Vladsz83 4f5d180
fix
Vladsz83 a25c2f2
review fixes
Vladsz83 4af4ccd
typo
Vladsz83 f863cc4
typo
Vladsz83 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...les/core/src/main/java/org/apache/ignite/internal/DistributedOperationContextMessage.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /* | ||
| * 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 org.apache.ignite.internal.thread.context.DistributedOperationContextManager; | ||
| import org.apache.ignite.internal.thread.context.OperationContext; | ||
| import org.apache.ignite.plugin.extensions.communication.Message; | ||
|
|
||
| /** | ||
| * Transport for {@link OperationContext} distributed attributes. | ||
| * | ||
| * @see DistributedOperationContextManager | ||
| */ | ||
| public class DistributedOperationContextMessage implements Message { | ||
| /** Values of operation context attributes. */ | ||
| @Order(0) | ||
| public Message[] vals; | ||
|
|
||
| /** Bitmap of effective attributes ids. */ | ||
| @Order(1) | ||
| public byte idBitmap; | ||
|
|
||
| /** Empty constructor for serialization purposes. */ | ||
| public DistributedOperationContextMessage() { | ||
| // No-op. | ||
| } | ||
| } |
128 changes: 128 additions & 0 deletions
128
...in/java/org/apache/ignite/internal/thread/context/DistributedOperationContextManager.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| /* | ||
| * 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.thread.context; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.concurrent.ConcurrentSkipListMap; | ||
| import org.apache.ignite.IgniteException; | ||
| import org.apache.ignite.internal.DistributedOperationContextMessage; | ||
| import org.apache.ignite.internal.util.typedef.F; | ||
| import org.apache.ignite.plugin.extensions.communication.Message; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| /** | ||
| * A manager of {@link OperationContextAttribute} which are required to be propagated through a cluster. | ||
| * Has own attributes ids compared to a local node's {@link OperationContext}. | ||
| * | ||
| * @see OperationContext | ||
| * @see DistributedOperationContextMessage | ||
| */ | ||
| public class DistributedOperationContextManager { | ||
| /** */ | ||
| private static final DistributedOperationContextManager INSTANCE = new DistributedOperationContextManager(); | ||
|
|
||
| /** Maximal number of supported distributed attributes. */ | ||
| static final byte MAX_DISTRIBUTED_ATTR_CNT = Byte.SIZE; | ||
|
|
||
| /** Registered distributed attributes by their cluster-wide id. */ | ||
| private final Map<Byte, OperationContextAttribute<? extends Message>> attrs = new ConcurrentSkipListMap<>(); | ||
|
|
||
| /** */ | ||
| public static DistributedOperationContextManager instance() { | ||
| return INSTANCE; | ||
| } | ||
|
|
||
| /** | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| * Creates and registers a distributable {@link OperationContextAttribute}. | ||
| * | ||
| * @param id Cluster-wide id of a distributed operation context attribute. | ||
| * @param initVal The attribute's unitial value. | ||
| */ | ||
| public <T extends Message> OperationContextAttribute<T> createDistributedAttribute(byte id, @Nullable T initVal) { | ||
| assert id >= 0 && id < MAX_DISTRIBUTED_ATTR_CNT : "Invalid distributed attributed id [id=" + id + ']'; | ||
|
|
||
| return (OperationContextAttribute<T>)attrs.compute(id, (id0, attr0) -> { | ||
| if (attr0 != null) | ||
| throw new IgniteException("Duplicated distributed attribute id [id=" + id + ']'); | ||
|
|
||
| return OperationContextAttribute.newInstance(initVal); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Requests current {@link OperationContext} for its effective attributes and collects ones which are also registered | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| * as distbibued attributes. | ||
| * | ||
| * @return A message to send current effective distributed attributes. {@code null}, if there are no | ||
| * effective attributes in {@link OperationContext} or none of them is a distributed attribute. | ||
| */ | ||
| public @Nullable DistributedOperationContextMessage collectDistributedAttributes() { | ||
| DistributedOperationContextMessage res = null; | ||
| List<Message> vals = null; | ||
|
|
||
| for (Map.Entry<Byte, OperationContextAttribute<? extends Message>> e : attrs.entrySet()) { | ||
| OperationContextAttribute<? extends Message> attr = e.getValue(); | ||
|
|
||
| Message curVal = OperationContext.get(attr); | ||
|
|
||
| if (curVal != attr.initialValue()) { | ||
| if (res == null) { | ||
| res = new DistributedOperationContextMessage(); | ||
|
|
||
| vals = new ArrayList<>(MAX_DISTRIBUTED_ATTR_CNT / 2); | ||
| } | ||
|
|
||
| byte mask = (byte)(1 << e.getKey()); | ||
|
|
||
| assert (res.idBitmap & mask) == 0; | ||
|
|
||
| vals.add(curVal); | ||
| res.idBitmap |= mask; | ||
| } | ||
| } | ||
|
|
||
| if (res != null) | ||
| res.vals = vals.toArray(vals.toArray(new Message[vals.size()])); | ||
|
|
||
| return res; | ||
| } | ||
|
|
||
| /** Sets the received distributed operation context attributes (if any) into current {@link OperationContext}. */ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| public Scope restoreDistributedAttributes(@Nullable DistributedOperationContextMessage msg) { | ||
| if (msg == null) | ||
| return Scope.NOOP_SCOPE; | ||
|
|
||
| assert msg.idBitmap != 0; | ||
| assert !F.isEmpty(msg.vals); | ||
| assert msg.vals.length <= MAX_DISTRIBUTED_ATTR_CNT; | ||
|
|
||
| OperationContext.ContextUpdater updater = OperationContext.ContextUpdater.create(); | ||
|
|
||
| for (byte valIdx = 0, maskIdx = 0; valIdx < msg.vals.length; ++valIdx) { | ||
| Message curVal = msg.vals[valIdx]; | ||
|
|
||
| while ((msg.idBitmap & (1 << maskIdx)) == 0) | ||
| ++maskIdx; | ||
|
|
||
| updater.set((OperationContextAttribute<Message>)attrs.get(maskIdx++), curVal); | ||
| } | ||
|
|
||
| return updater.apply(); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.