xtern commented on a change in pull request #7941:
URL: https://github.com/apache/ignite/pull/7941#discussion_r478319579



##########
File path: 
modules/core/src/main/java/org/apache/ignite/internal/managers/encryption/GroupKeyChangeProcess.java
##########
@@ -0,0 +1,336 @@
+/*
+ * 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.managers.encryption;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.IgniteFeatures;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import 
org.apache.ignite.internal.managers.encryption.GridEncryptionManager.EmptyResult;
+import 
org.apache.ignite.internal.managers.encryption.GridEncryptionManager.KeyChangeFuture;
+import org.apache.ignite.internal.processors.cache.CacheGroupContext;
+import org.apache.ignite.internal.processors.cache.IgniteInternalCache;
+import org.apache.ignite.internal.util.distributed.DistributedProcess;
+import org.apache.ignite.internal.util.future.GridFinishedFuture;
+import org.apache.ignite.internal.util.future.GridFutureAdapter;
+import org.apache.ignite.internal.util.future.IgniteFinishedFutureImpl;
+import org.apache.ignite.internal.util.future.IgniteFutureImpl;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteFuture;
+import org.apache.ignite.lang.IgniteFutureCancelledException;
+
+import static org.apache.ignite.internal.IgniteFeatures.CACHE_GROUP_KEY_CHANGE;
+import static 
org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.CACHE_GROUP_KEY_CHANGE_FINISH;
+import static 
org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.CACHE_GROUP_KEY_CHANGE_PREPARE;
+
+/**
+ * Two phase distributed process, that performs cache group encryption key 
rotation.
+ */
+class GroupKeyChangeProcess {
+    /** Grid kernal context. */
+    private final GridKernalContext ctx;
+
+    /** Cache group encyption key change prepare phase. */
+    private final DistributedProcess<ChangeCacheEncryptionRequest, 
EmptyResult> prepareGKChangeProc;
+
+    /** Cache group encyption key change perform phase. */
+    private final DistributedProcess<ChangeCacheEncryptionRequest, 
EmptyResult> performGKChangeProc;
+
+    /** Group encryption keys. */
+    private final CacheGroupEncryptionKeys keys;
+
+    /** Cache group key change future. */
+    private volatile GroupKeyChangeFuture fut;
+
+    /** Cache group key change request. */
+    private volatile ChangeCacheEncryptionRequest req;
+
+    /**
+     * @param ctx Grid kernal context.
+     */
+    GroupKeyChangeProcess(GridKernalContext ctx, CacheGroupEncryptionKeys 
keys) {
+        this.ctx = ctx;
+        this.keys = keys;
+
+        prepareGKChangeProc =
+            new DistributedProcess<>(ctx, CACHE_GROUP_KEY_CHANGE_PREPARE, 
this::prepare, this::finishPrepare);
+        performGKChangeProc =
+            new DistributedProcess<>(ctx, CACHE_GROUP_KEY_CHANGE_FINISH, 
this::perform, this::finishPerform);
+    }
+
+    /**
+     * @return {@code True} if operation is still in progress.
+     */
+    public boolean started() {
+        return req != null;
+    }
+
+    /**
+     * @return {@code True} if operation is not finished.
+     */
+    public boolean finished() {
+        IgniteInternalFuture<Void> fut0 = fut;
+
+        return fut0 == null || fut0.isDone();
+    }
+
+    /**
+     * @param msg Error message.
+     */
+    public void cancel(String msg) {
+        GridFutureAdapter<Void> keyChangeFut = fut;
+
+        if (keyChangeFut != null && !keyChangeFut.isDone())
+            keyChangeFut.onDone(new IgniteFutureCancelledException(msg));
+    }
+
+    /**
+     * Starts cache group encryption key change process.
+     *
+     * @param cacheOrGrpNames Cache or group names.
+     */
+    public IgniteFuture<Void> start(Collection<String> cacheOrGrpNames) {
+        if (ctx.clientNode())
+            throw new UnsupportedOperationException("Client and daemon nodes 
can not perform this operation.");
+
+        if (!IgniteFeatures.allNodesSupports(ctx.grid().cluster().nodes(), 
CACHE_GROUP_KEY_CHANGE))
+            throw new IllegalStateException("Not all nodes in the cluster 
support this operation.");
+
+        if (!ctx.state().clusterState().state().active())
+            throw new IgniteException("Operation was rejected. The cluster is 
inactive.");
+
+        if (!finished()) {
+            return new IgniteFinishedFutureImpl<>(new IgniteException("Cache 
group key change was rejected. " +
+                "The previous change was not completed."));
+        }
+
+        int[] grpIds = new int[cacheOrGrpNames.size()];
+        byte[] keyIds = new byte[grpIds.length];
+
+        int n = 0;
+
+        for (String cacheOrGroupName : cacheOrGrpNames) {
+            CacheGroupContext grp = 
ctx.cache().cacheGroup(CU.cacheId(cacheOrGroupName));

Review comment:
       Changed to descriptors, added test with node filter




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to