You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "PakhomovAlexander (via GitHub)" <gi...@apache.org> on 2023/05/16 12:50:53 UTC

[GitHub] [ignite-3] PakhomovAlexander commented on a diff in pull request #2044: IGNITE-19384 Update deployment units after deploy

PakhomovAlexander commented on code in PR #2044:
URL: https://github.com/apache/ignite-3/pull/2044#discussion_r1195006093


##########
modules/code-deployment/src/main/java/org/apache/ignite/internal/deployunit/DeployMessagingService.java:
##########
@@ -115,33 +110,19 @@ public void subscribe() {
      * @param unitContent Deployment unit file names and content.

Review Comment:
   Add `node` description, please.



##########
modules/code-deployment/src/main/java/org/apache/ignite/internal/deployunit/DeploymentManagerImpl.java:
##########
@@ -176,17 +143,53 @@ public CompletableFuture<Boolean> deployAsync(String id, Version version, boolea
                 });
     }
 
+    private CompletableFuture<Boolean> doDeploy(String id, Version version, DeploymentUnit deploymentUnit) {
+        Map<String, byte[]> unitContent;
+        try {
+            unitContent = deploymentUnit.content().entrySet().stream()
+                    .collect(Collectors.toMap(Map.Entry::getKey, entry -> readContent(entry.getValue())));
+        } catch (DeploymentUnitReadException e) {
+            return failedFuture(e);
+        }
+        return tracker.track(id, version, deployer.deploy(id, version.render(), unitContent)
+                .thenCompose(deployed -> {

Review Comment:
   I don't really get the reason for `thenCompose` block here. Could you explain why we have `thenCompose` and `thenApply` here? Looks like the whole logic is done in `thenApply`.



##########
modules/code-deployment/src/main/java/org/apache/ignite/internal/deployunit/metastore/DeploymentUnitMetastoreImpl.java:
##########
@@ -0,0 +1,199 @@
+/*
+ * 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.deployunit.metastore;
+
+import static java.util.concurrent.CompletableFuture.completedFuture;
+import static org.apache.ignite.internal.deployunit.metastore.key.UnitKey.allUnits;
+import static org.apache.ignite.internal.deployunit.metastore.key.UnitKey.clusterStatusKey;
+import static org.apache.ignite.internal.deployunit.metastore.key.UnitKey.nodeStatusKey;
+import static org.apache.ignite.internal.deployunit.metastore.key.UnitKey.nodes;
+import static org.apache.ignite.internal.deployunit.metastore.key.UnitMetaSerializer.deserialize;
+import static org.apache.ignite.internal.deployunit.metastore.key.UnitMetaSerializer.serialize;
+import static org.apache.ignite.internal.metastorage.dsl.Conditions.exists;
+import static org.apache.ignite.internal.metastorage.dsl.Conditions.notExists;
+import static org.apache.ignite.internal.metastorage.dsl.Conditions.revision;
+import static org.apache.ignite.internal.metastorage.dsl.Operations.noop;
+import static org.apache.ignite.internal.metastorage.dsl.Operations.put;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.apache.ignite.internal.deployunit.UnitMeta;
+import org.apache.ignite.internal.deployunit.UnitStatus;
+import org.apache.ignite.internal.deployunit.version.Version;
+import org.apache.ignite.internal.metastorage.MetaStorageManager;
+import org.apache.ignite.internal.metastorage.dsl.Condition;
+import org.apache.ignite.internal.metastorage.dsl.Conditions;
+import org.apache.ignite.internal.metastorage.dsl.Operation;
+import org.apache.ignite.internal.metastorage.dsl.Operations;
+import org.apache.ignite.internal.rest.api.deployment.DeploymentStatus;
+import org.apache.ignite.lang.ByteArray;
+
+/**
+ * Implementation of {@link DeploymentUnitMetastore} based on {@link MetaStorageManager}.
+ */
+public class DeploymentUnitMetastoreImpl implements DeploymentUnitMetastore {
+    private final MetaStorageManager metaStorage;
+
+    public DeploymentUnitMetastoreImpl(MetaStorageManager metaStorage) {
+        this.metaStorage = metaStorage;
+    }
+
+    @Override
+    public CompletableFuture<UnitMeta> getClusterStatus(String id, Version version) {
+        return metaStorage.get(clusterStatusKey(id, version)).thenApply(entry -> {
+            byte[] value = entry.value();
+            if (value == null) {
+                return null;
+            }
+
+            return deserialize(value);
+        });
+    }
+
+    @Override
+    public CompletableFuture<UnitMeta> getNodeStatus(String id, Version version, String nodeId) {
+        return metaStorage.get(nodeStatusKey(id, version, nodeId)).thenApply(entry -> {
+            byte[] value = entry.value();
+            if (value == null) {
+                return null;
+            }
+
+            return deserialize(value);
+        });
+    }
+
+    @Override
+    public CompletableFuture<List<UnitStatus>> getAllClusterStatuses() {
+        CompletableFuture<List<UnitStatus>> result = new CompletableFuture<>();
+        metaStorage.prefix(allUnits()).subscribe(new UnitsAccumulator().toSubscriber(result));
+        return result;
+    }
+
+    private CompletableFuture<List<UnitStatus>> getClusterStatuses(Predicate<UnitMeta> filter) {
+        CompletableFuture<List<UnitStatus>> result = new CompletableFuture<>();
+        metaStorage.prefix(allUnits()).subscribe(new UnitsAccumulator(filter).toSubscriber(result));
+        return result;
+    }
+
+    @Override
+    public CompletableFuture<UnitStatus> getClusterStatuses(String id) {
+        CompletableFuture<UnitStatus> result = new CompletableFuture<>();
+        metaStorage.prefix(allUnits()).subscribe(new ClusterStatusAccumulator(id).toSubscriber(result));
+        return result;
+    }
+
+    @Override
+    public CompletableFuture<Boolean> createClusterStatus(String id, Version version) {
+        ByteArray key = clusterStatusKey(id, version);
+        byte[] value = serialize(new UnitMeta(id, version, DeploymentStatus.UPLOADING));
+
+        return metaStorage.invoke(notExists(key), put(key, value), noop());
+    }
+
+    @Override
+    public CompletableFuture<Boolean> createNodeStatus(String id, Version version, String nodeId) {
+        ByteArray key = nodeStatusKey(id, version, nodeId);
+        byte[] value = serialize(new UnitMeta(id, version, DeploymentStatus.UPLOADING));
+        return metaStorage.invoke(notExists(key), put(key, value), noop());
+    }
+
+    @Override
+    public CompletableFuture<Boolean> updateClusterStatus(String id, Version version, DeploymentStatus status) {
+        return updateStatus(clusterStatusKey(id, version), status);
+    }
+
+    @Override
+    public CompletableFuture<Boolean> updateNodeStatus(String id, Version version, String nodeId, DeploymentStatus status) {
+        return updateStatus(nodeStatusKey(id, version, nodeId), status);
+    }
+
+    @Override
+    public CompletableFuture<List<UnitStatus>> findAllByNodeConsistentId(String nodeId) {
+        CompletableFuture<List<String>> result = new CompletableFuture<>();
+        metaStorage.prefix(nodes()).subscribe(new UnitsByNodeAccumulator(nodeId).toSubscriber(result));
+        return result.thenCompose(ids -> getClusterStatuses(meta -> ids.contains(meta.id())));
+    }
+
+    @Override
+    public CompletableFuture<Boolean> remove(String id, Version version) {
+        ByteArray key = clusterStatusKey(id, version);
+        CompletableFuture<List<byte[]>> nodesFuture = new CompletableFuture<>();
+        metaStorage.prefix(nodes(id, version)).subscribe(new KeyAccumulator().toSubscriber(nodesFuture));
+
+        return nodesFuture.thenCompose(nodes ->
+            metaStorage.invoke(existsAll(key, nodes), removeAll(key, nodes), Collections.emptyList())
+        );
+    }
+
+    private Condition existsAll(ByteArray key, List<byte[]> keys) {
+        Condition result = exists(key);

Review Comment:
   This can be inlined. `result` is not the best name I think.



##########
modules/code-deployment/src/main/java/org/apache/ignite/internal/deployunit/DeployMessagingService.java:
##########
@@ -115,33 +110,19 @@ public void subscribe() {
      * @param unitContent Deployment unit file names and content.
      * @return Future with deployment result.
      */
-    public CompletableFuture<List<String>> startDeployAsyncToCmg(String id, Version version, Map<String, byte[]> unitContent) {
+    public CompletableFuture<Boolean> startDeployAsyncToNode(
+            String id,
+            Version version,
+            Map<String, byte[]> unitContent,
+            String node

Review Comment:
   ```suggestion
               String consistentId
   ```



##########
modules/code-deployment/src/main/java/org/apache/ignite/internal/deployunit/DeploymentManagerImpl.java:
##########
@@ -176,17 +143,53 @@ public CompletableFuture<Boolean> deployAsync(String id, Version version, boolea
                 });
     }
 
+    private CompletableFuture<Boolean> doDeploy(String id, Version version, DeploymentUnit deploymentUnit) {
+        Map<String, byte[]> unitContent;
+        try {
+            unitContent = deploymentUnit.content().entrySet().stream()
+                    .collect(Collectors.toMap(Map.Entry::getKey, entry -> readContent(entry.getValue())));
+        } catch (DeploymentUnitReadException e) {
+            return failedFuture(e);
+        }

Review Comment:
   I think this try-catch block can be  moved to a separate method like `readUnitContent`



##########
modules/code-deployment/src/main/java/org/apache/ignite/internal/deployunit/metastore/DeploymentUnitMetastoreImpl.java:
##########
@@ -0,0 +1,199 @@
+/*
+ * 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.deployunit.metastore;
+
+import static java.util.concurrent.CompletableFuture.completedFuture;
+import static org.apache.ignite.internal.deployunit.metastore.key.UnitKey.allUnits;
+import static org.apache.ignite.internal.deployunit.metastore.key.UnitKey.clusterStatusKey;
+import static org.apache.ignite.internal.deployunit.metastore.key.UnitKey.nodeStatusKey;
+import static org.apache.ignite.internal.deployunit.metastore.key.UnitKey.nodes;
+import static org.apache.ignite.internal.deployunit.metastore.key.UnitMetaSerializer.deserialize;
+import static org.apache.ignite.internal.deployunit.metastore.key.UnitMetaSerializer.serialize;
+import static org.apache.ignite.internal.metastorage.dsl.Conditions.exists;
+import static org.apache.ignite.internal.metastorage.dsl.Conditions.notExists;
+import static org.apache.ignite.internal.metastorage.dsl.Conditions.revision;
+import static org.apache.ignite.internal.metastorage.dsl.Operations.noop;
+import static org.apache.ignite.internal.metastorage.dsl.Operations.put;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.apache.ignite.internal.deployunit.UnitMeta;
+import org.apache.ignite.internal.deployunit.UnitStatus;
+import org.apache.ignite.internal.deployunit.version.Version;
+import org.apache.ignite.internal.metastorage.MetaStorageManager;
+import org.apache.ignite.internal.metastorage.dsl.Condition;
+import org.apache.ignite.internal.metastorage.dsl.Conditions;
+import org.apache.ignite.internal.metastorage.dsl.Operation;
+import org.apache.ignite.internal.metastorage.dsl.Operations;
+import org.apache.ignite.internal.rest.api.deployment.DeploymentStatus;
+import org.apache.ignite.lang.ByteArray;
+
+/**
+ * Implementation of {@link DeploymentUnitMetastore} based on {@link MetaStorageManager}.
+ */
+public class DeploymentUnitMetastoreImpl implements DeploymentUnitMetastore {
+    private final MetaStorageManager metaStorage;
+
+    public DeploymentUnitMetastoreImpl(MetaStorageManager metaStorage) {
+        this.metaStorage = metaStorage;
+    }
+
+    @Override
+    public CompletableFuture<UnitMeta> getClusterStatus(String id, Version version) {
+        return metaStorage.get(clusterStatusKey(id, version)).thenApply(entry -> {
+            byte[] value = entry.value();
+            if (value == null) {
+                return null;
+            }
+
+            return deserialize(value);
+        });
+    }
+
+    @Override
+    public CompletableFuture<UnitMeta> getNodeStatus(String id, Version version, String nodeId) {
+        return metaStorage.get(nodeStatusKey(id, version, nodeId)).thenApply(entry -> {
+            byte[] value = entry.value();
+            if (value == null) {
+                return null;
+            }
+
+            return deserialize(value);
+        });
+    }
+
+    @Override
+    public CompletableFuture<List<UnitStatus>> getAllClusterStatuses() {
+        CompletableFuture<List<UnitStatus>> result = new CompletableFuture<>();
+        metaStorage.prefix(allUnits()).subscribe(new UnitsAccumulator().toSubscriber(result));
+        return result;
+    }
+
+    private CompletableFuture<List<UnitStatus>> getClusterStatuses(Predicate<UnitMeta> filter) {
+        CompletableFuture<List<UnitStatus>> result = new CompletableFuture<>();
+        metaStorage.prefix(allUnits()).subscribe(new UnitsAccumulator(filter).toSubscriber(result));
+        return result;
+    }
+
+    @Override
+    public CompletableFuture<UnitStatus> getClusterStatuses(String id) {
+        CompletableFuture<UnitStatus> result = new CompletableFuture<>();
+        metaStorage.prefix(allUnits()).subscribe(new ClusterStatusAccumulator(id).toSubscriber(result));
+        return result;
+    }
+
+    @Override
+    public CompletableFuture<Boolean> createClusterStatus(String id, Version version) {
+        ByteArray key = clusterStatusKey(id, version);
+        byte[] value = serialize(new UnitMeta(id, version, DeploymentStatus.UPLOADING));
+
+        return metaStorage.invoke(notExists(key), put(key, value), noop());
+    }
+
+    @Override
+    public CompletableFuture<Boolean> createNodeStatus(String id, Version version, String nodeId) {
+        ByteArray key = nodeStatusKey(id, version, nodeId);
+        byte[] value = serialize(new UnitMeta(id, version, DeploymentStatus.UPLOADING));
+        return metaStorage.invoke(notExists(key), put(key, value), noop());
+    }
+
+    @Override
+    public CompletableFuture<Boolean> updateClusterStatus(String id, Version version, DeploymentStatus status) {
+        return updateStatus(clusterStatusKey(id, version), status);
+    }
+
+    @Override
+    public CompletableFuture<Boolean> updateNodeStatus(String id, Version version, String nodeId, DeploymentStatus status) {
+        return updateStatus(nodeStatusKey(id, version, nodeId), status);
+    }
+
+    @Override
+    public CompletableFuture<List<UnitStatus>> findAllByNodeConsistentId(String nodeId) {
+        CompletableFuture<List<String>> result = new CompletableFuture<>();
+        metaStorage.prefix(nodes()).subscribe(new UnitsByNodeAccumulator(nodeId).toSubscriber(result));
+        return result.thenCompose(ids -> getClusterStatuses(meta -> ids.contains(meta.id())));

Review Comment:
   This code generates too many requests to metastorage. You select all nodes (x), then in `getClusterStatuses` you select all units x times and filter that by node id x times. 
   
   I think we can optimize this part.



##########
modules/code-deployment/src/main/java/org/apache/ignite/internal/deployunit/metastore/DeploymentUnitMetastore.java:
##########
@@ -0,0 +1,122 @@
+/*
+ * 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.deployunit.metastore;
+
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.internal.deployunit.UnitMeta;
+import org.apache.ignite.internal.deployunit.UnitStatus;
+import org.apache.ignite.internal.deployunit.version.Version;
+import org.apache.ignite.internal.rest.api.deployment.DeploymentStatus;
+
+/**
+ * Metastore for deployment units.
+ */
+public interface DeploymentUnitMetastore {
+    /**
+     * Returns cluster status of deployment unit.
+     *
+     * @param id Deployment unit identifier.
+     * @param version Deployment unit version.
+     * @return Cluster status of deployment unit.
+     */
+    CompletableFuture<UnitMeta> getClusterStatus(String id, Version version);
+
+    /**
+     * Returns node status of deployment unit.
+     *
+     * @param id Deployment unit identifier.
+     * @param version Deployment unit version.
+     * @param nodeId Node consistent identifier.
+     * @return Node status of deployment unit.
+     */
+    CompletableFuture<UnitMeta> getNodeStatus(String id, Version version, String nodeId);
+
+    /**
+     * Returns cluster statuses of all existed deployment units.
+     *
+     * @return Cluster statuses of all existed deployment units.
+     */
+    CompletableFuture<List<UnitStatus>> getAllClusterStatuses();
+
+    /**
+     * Returns cluster status of deployment unit with provided identifier.
+     *
+     * @param id Deployment unit identifier.
+     * @return Cluster status of deployment unit with provided identifier.
+     */
+    CompletableFuture<UnitStatus> getClusterStatuses(String id);

Review Comment:
   It is a little bit confusing to have `UnitStatus` and `UnitMeta`. What is the exact difference? Maybe we could rename them like `NodeUnitStatus` and `ClusterUnitStatus` or something like that.



##########
modules/code-deployment/src/main/java/org/apache/ignite/internal/deployunit/metastore/DeploymentUnitMetastore.java:
##########
@@ -0,0 +1,122 @@
+/*
+ * 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.deployunit.metastore;
+
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.internal.deployunit.UnitMeta;
+import org.apache.ignite.internal.deployunit.UnitStatus;
+import org.apache.ignite.internal.deployunit.version.Version;
+import org.apache.ignite.internal.rest.api.deployment.DeploymentStatus;
+
+/**
+ * Metastore for deployment units.
+ */
+public interface DeploymentUnitMetastore {

Review Comment:
   I think the "Metastore" here could be renamed to "Store". Because you do not expose the metastore API like Publishers, Revision numbers, etc. 



##########
modules/code-deployment/src/main/java/org/apache/ignite/internal/deployunit/metastore/UnitsByNodeAccumulator.java:
##########
@@ -0,0 +1,61 @@
+/*
+ * 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.deployunit.metastore;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import org.apache.ignite.internal.deployunit.UnitMeta;
+import org.apache.ignite.internal.deployunit.metastore.key.UnitKey;
+import org.apache.ignite.internal.deployunit.metastore.key.UnitMetaSerializer;
+import org.apache.ignite.internal.metastorage.Entry;
+import org.apache.ignite.internal.rest.api.deployment.DeploymentStatus;
+import org.apache.ignite.internal.util.subscription.AccumulateException;
+import org.apache.ignite.internal.util.subscription.Accumulator;
+
+/**
+ * Units id accumulator for by node deployment.

Review Comment:
   Could you mention here that it accumulates only DEPLOYED statuses?



##########
modules/code-deployment/src/main/java/org/apache/ignite/internal/deployunit/metastore/DeploymentUnitMetastoreImpl.java:
##########
@@ -0,0 +1,199 @@
+/*
+ * 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.deployunit.metastore;
+
+import static java.util.concurrent.CompletableFuture.completedFuture;
+import static org.apache.ignite.internal.deployunit.metastore.key.UnitKey.allUnits;
+import static org.apache.ignite.internal.deployunit.metastore.key.UnitKey.clusterStatusKey;
+import static org.apache.ignite.internal.deployunit.metastore.key.UnitKey.nodeStatusKey;
+import static org.apache.ignite.internal.deployunit.metastore.key.UnitKey.nodes;
+import static org.apache.ignite.internal.deployunit.metastore.key.UnitMetaSerializer.deserialize;
+import static org.apache.ignite.internal.deployunit.metastore.key.UnitMetaSerializer.serialize;
+import static org.apache.ignite.internal.metastorage.dsl.Conditions.exists;
+import static org.apache.ignite.internal.metastorage.dsl.Conditions.notExists;
+import static org.apache.ignite.internal.metastorage.dsl.Conditions.revision;
+import static org.apache.ignite.internal.metastorage.dsl.Operations.noop;
+import static org.apache.ignite.internal.metastorage.dsl.Operations.put;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.apache.ignite.internal.deployunit.UnitMeta;
+import org.apache.ignite.internal.deployunit.UnitStatus;
+import org.apache.ignite.internal.deployunit.version.Version;
+import org.apache.ignite.internal.metastorage.MetaStorageManager;
+import org.apache.ignite.internal.metastorage.dsl.Condition;
+import org.apache.ignite.internal.metastorage.dsl.Conditions;
+import org.apache.ignite.internal.metastorage.dsl.Operation;
+import org.apache.ignite.internal.metastorage.dsl.Operations;
+import org.apache.ignite.internal.rest.api.deployment.DeploymentStatus;
+import org.apache.ignite.lang.ByteArray;
+
+/**
+ * Implementation of {@link DeploymentUnitMetastore} based on {@link MetaStorageManager}.
+ */
+public class DeploymentUnitMetastoreImpl implements DeploymentUnitMetastore {
+    private final MetaStorageManager metaStorage;
+
+    public DeploymentUnitMetastoreImpl(MetaStorageManager metaStorage) {
+        this.metaStorage = metaStorage;
+    }
+
+    @Override
+    public CompletableFuture<UnitMeta> getClusterStatus(String id, Version version) {
+        return metaStorage.get(clusterStatusKey(id, version)).thenApply(entry -> {
+            byte[] value = entry.value();
+            if (value == null) {
+                return null;
+            }
+
+            return deserialize(value);
+        });
+    }
+
+    @Override
+    public CompletableFuture<UnitMeta> getNodeStatus(String id, Version version, String nodeId) {
+        return metaStorage.get(nodeStatusKey(id, version, nodeId)).thenApply(entry -> {
+            byte[] value = entry.value();
+            if (value == null) {
+                return null;
+            }
+
+            return deserialize(value);
+        });
+    }
+
+    @Override
+    public CompletableFuture<List<UnitStatus>> getAllClusterStatuses() {
+        CompletableFuture<List<UnitStatus>> result = new CompletableFuture<>();
+        metaStorage.prefix(allUnits()).subscribe(new UnitsAccumulator().toSubscriber(result));
+        return result;
+    }
+
+    private CompletableFuture<List<UnitStatus>> getClusterStatuses(Predicate<UnitMeta> filter) {
+        CompletableFuture<List<UnitStatus>> result = new CompletableFuture<>();
+        metaStorage.prefix(allUnits()).subscribe(new UnitsAccumulator(filter).toSubscriber(result));
+        return result;
+    }
+
+    @Override
+    public CompletableFuture<UnitStatus> getClusterStatuses(String id) {
+        CompletableFuture<UnitStatus> result = new CompletableFuture<>();
+        metaStorage.prefix(allUnits()).subscribe(new ClusterStatusAccumulator(id).toSubscriber(result));
+        return result;
+    }
+
+    @Override
+    public CompletableFuture<Boolean> createClusterStatus(String id, Version version) {
+        ByteArray key = clusterStatusKey(id, version);
+        byte[] value = serialize(new UnitMeta(id, version, DeploymentStatus.UPLOADING));
+
+        return metaStorage.invoke(notExists(key), put(key, value), noop());
+    }
+
+    @Override
+    public CompletableFuture<Boolean> createNodeStatus(String id, Version version, String nodeId) {
+        ByteArray key = nodeStatusKey(id, version, nodeId);
+        byte[] value = serialize(new UnitMeta(id, version, DeploymentStatus.UPLOADING));
+        return metaStorage.invoke(notExists(key), put(key, value), noop());
+    }
+
+    @Override
+    public CompletableFuture<Boolean> updateClusterStatus(String id, Version version, DeploymentStatus status) {
+        return updateStatus(clusterStatusKey(id, version), status);
+    }
+
+    @Override
+    public CompletableFuture<Boolean> updateNodeStatus(String id, Version version, String nodeId, DeploymentStatus status) {
+        return updateStatus(nodeStatusKey(id, version, nodeId), status);
+    }
+
+    @Override
+    public CompletableFuture<List<UnitStatus>> findAllByNodeConsistentId(String nodeId) {
+        CompletableFuture<List<String>> result = new CompletableFuture<>();
+        metaStorage.prefix(nodes()).subscribe(new UnitsByNodeAccumulator(nodeId).toSubscriber(result));
+        return result.thenCompose(ids -> getClusterStatuses(meta -> ids.contains(meta.id())));
+    }
+
+    @Override
+    public CompletableFuture<Boolean> remove(String id, Version version) {
+        ByteArray key = clusterStatusKey(id, version);
+        CompletableFuture<List<byte[]>> nodesFuture = new CompletableFuture<>();
+        metaStorage.prefix(nodes(id, version)).subscribe(new KeyAccumulator().toSubscriber(nodesFuture));
+
+        return nodesFuture.thenCompose(nodes ->
+            metaStorage.invoke(existsAll(key, nodes), removeAll(key, nodes), Collections.emptyList())
+        );
+    }
+
+    private Condition existsAll(ByteArray key, List<byte[]> keys) {

Review Comment:
   ```suggestion
       private Condition existsAll(ByteArray key, List<byte[]> nodesKeys) {
   ```



##########
modules/code-deployment/src/main/java/org/apache/ignite/internal/deployunit/UnitMeta.java:
##########
@@ -131,28 +89,15 @@ public boolean equals(Object o) {
 
         UnitMeta meta = (UnitMeta) o;
 
-        if (id != null ? !id.equals(meta.id) : meta.id != null) {
-            return false;
-        }
-        if (version != null ? !version.equals(meta.version) : meta.version != null) {
-            return false;
-        }
-        if (fileNames != null ? !fileNames.equals(meta.fileNames) : meta.fileNames != null) {
-            return false;
-        }
-        if (status != meta.status) {
-            return false;
-        }
-        return consistentIdLocation.equals(meta.consistentIdLocation);
+        return (id != null ? id.equals(meta.id) : meta.id == null)

Review Comment:
   I liked the previous variant 😀.



##########
modules/code-deployment/src/test/java/org/apache/ignite/deployment/metastore/DeploymentUnitMetastoreImplTest.java:
##########
@@ -0,0 +1,168 @@
+/*
+ * 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.deployment.metastore;
+
+import static org.apache.ignite.internal.rest.api.deployment.DeploymentStatus.DEPLOYED;
+import static org.apache.ignite.internal.rest.api.deployment.DeploymentStatus.UPLOADING;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willBe;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.hamcrest.Matchers.equalTo;
+
+import java.nio.file.Path;
+import java.util.Collections;
+import java.util.List;
+import org.apache.ignite.internal.deployunit.UnitMeta;
+import org.apache.ignite.internal.deployunit.UnitStatus;
+import org.apache.ignite.internal.deployunit.metastore.DeploymentUnitMetastoreImpl;
+import org.apache.ignite.internal.deployunit.version.Version;
+import org.apache.ignite.internal.metastorage.MetaStorageManager;
+import org.apache.ignite.internal.metastorage.impl.StandaloneMetaStorageManager;
+import org.apache.ignite.internal.metastorage.server.KeyValueStorage;
+import org.apache.ignite.internal.metastorage.server.persistence.RocksDbKeyValueStorage;
+import org.apache.ignite.internal.testframework.WorkDirectory;
+import org.apache.ignite.internal.testframework.WorkDirectoryExtension;
+import org.apache.ignite.internal.vault.VaultManager;
+import org.apache.ignite.internal.vault.inmemory.InMemoryVaultService;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Test suite for {@link DeploymentUnitMetastoreImpl}.
+ */
+@ExtendWith(WorkDirectoryExtension.class)
+public class DeploymentUnitMetastoreImplTest {
+
+    private final VaultManager vaultManager = new VaultManager(new InMemoryVaultService());
+
+    private DeploymentUnitMetastoreImpl metastore;
+
+    @WorkDirectory
+    private Path workDir;
+
+    @BeforeEach
+    public void setup() {
+        KeyValueStorage storage = new RocksDbKeyValueStorage("test", workDir);
+
+        MetaStorageManager metaStorageManager = StandaloneMetaStorageManager.create(vaultManager, storage);
+
+        vaultManager.start();
+        metaStorageManager.start();
+
+        metastore = new DeploymentUnitMetastoreImpl(metaStorageManager);
+    }
+
+    @Test
+    public void clusterStatusTest() {
+        String id = "id1";
+        Version version = Version.parseVersion("1.1.1");
+
+        assertThat(metastore.createClusterStatus(id, version), willBe(true));
+
+        assertThat(metastore.getClusterStatus(id, version),
+                willBe(new UnitMeta(id, version, UPLOADING)));
+
+        assertThat(metastore.updateClusterStatus(id, version, DEPLOYED), willBe(true));
+        assertThat(metastore.getClusterStatus(id, version),
+                willBe(new UnitMeta(id, version, DEPLOYED)));
+
+        assertThat(metastore.remove(id, version), willBe(true));
+
+        assertThat(metastore.getClusterStatus(id, version), willBe((UnitMeta) null));
+    }
+
+    @Test
+    public void nodeStatusTest() {
+        String id = "id2";
+        Version version = Version.parseVersion("1.1.1");
+
+        String node1 = "node1";
+        String node2 = "node2";
+        String node3 = "node3";
+
+        assertThat(metastore.createClusterStatus(id, version), willBe(true));
+        assertThat(metastore.getClusterStatus(id, version),
+                willBe(new UnitMeta(id, version, UPLOADING)));
+
+        assertThat(metastore.createNodeStatus(id, version, node1), willBe(true));
+        assertThat(metastore.getNodeStatus(id, version, node1),
+                willBe(new UnitMeta(id, version, UPLOADING)));
+
+        assertThat(metastore.updateNodeStatus(id, version, node1, DEPLOYED), willBe(true));
+        assertThat(metastore.getNodeStatus(id, version, node1),
+                willBe(new UnitMeta(id, version, DEPLOYED)));
+
+        assertThat(metastore.createNodeStatus(id, version, node2), willBe(true));
+        assertThat(metastore.getNodeStatus(id, version, node2),
+                willBe(new UnitMeta(id, version, UPLOADING)));
+
+        assertThat(metastore.createNodeStatus(id, version, node3), willBe(true));
+
+        assertThat(metastore.updateClusterStatus(id, version, DEPLOYED), willBe(true));
+        assertThat(metastore.getClusterStatus(id, version),
+                willBe(new UnitMeta(id, version, DEPLOYED)));
+
+        assertThat(metastore.getClusterStatuses(id),
+                willBe(UnitStatus.builder(id).append(version, DEPLOYED).build())
+        );
+
+        assertThat(metastore.remove(id, version), willBe(true));
+        assertThat(metastore.getNodeStatus(id, version, node1),
+                willBe((UnitMeta) null));
+    }
+
+    @Test
+    public void findByNodeId() {
+        String id1 = "id3";
+        String id2 = "id4";
+        Version version = Version.parseVersion("1.1.1");
+
+        String node1 = "node1";
+        String node2 = "node2";
+        String node3 = "node3";
+
+        assertThat(metastore.createClusterStatus(id1, version), willBe(true));
+        assertThat(metastore.createNodeStatus(id1, version, node1), willBe(true));
+        assertThat(metastore.createNodeStatus(id1, version, node2), willBe(true));
+        assertThat(metastore.createNodeStatus(id1, version, node3), willBe(true));
+
+        assertThat(metastore.createClusterStatus(id2, version), willBe(true));
+        assertThat(metastore.updateClusterStatus(id2, version, DEPLOYED), willBe(true));
+        assertThat(metastore.getClusterStatus(id2, version), willBe(new UnitMeta(id2, version, DEPLOYED)));
+
+        assertThat(metastore.createNodeStatus(id2, version, node1), willBe(true));
+        assertThat(metastore.createNodeStatus(id2, version, node2), willBe(true));
+        assertThat(metastore.createNodeStatus(id2, version, node3), willBe(true));
+
+        assertThat(metastore.findAllByNodeConsistentId(node1), willBe(Collections.emptyList()));
+
+        assertThat(metastore.updateNodeStatus(id1, version, node1, DEPLOYED), willBe(true));
+        assertThat(metastore.findAllByNodeConsistentId(node1), willBe(equalTo(
+                List.of(UnitStatus.builder(id1).append(version, UPLOADING).build())

Review Comment:
   Here you've changed the status for node1 with `id1` to `DEPLOYED` but the assertion says `UPLOADING`. I don't understand why.



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

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org