You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2021/09/20 11:16:29 UTC

[GitHub] [ignite] xtern commented on a change in pull request #9422: IGNITE-12971: Create snapshot view to show available cluster snapshots.

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



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteSnapshotManager.java
##########
@@ -1750,6 +1768,53 @@ static void copy(FileIOFactory factory, File from, File to, long length) {
         return new IgniteFutureImpl<>(cctx.kernalContext().task().execute(taskCls, snpName));
     }
 
+    /**
+     * Snapshots view supplier.
+     *
+     * @param filter Filter.
+     */
+    private Iterable<SnapshotView> snapshotViewSupplier(Map<String, Object> filter) {
+        List<String> snapshotNames = localSnapshotNames();
+
+        String snapshotName = (String)filter.get(SnapshotViewWalker.SNAPSHOT_NAME_FILTER);
+        String nodeConsistentId = (String)filter.get(SnapshotViewWalker.NODE_CONSISTENT_ID_FILTER);
+
+        return F.flat(F.iterator(snapshotNames, snpName -> {
+                if (snapshotName != null && !snapshotName.equals(snpName))
+                    return Collections.emptyList();
+
+                return F.flat(F.iterator(readSnapshotMetadatas(snpName), meta -> {
+                        if (nodeConsistentId != null && !nodeConsistentId.equals(toStringSafe(meta.consistentId())))

Review comment:
       1. meta.consistentId() is already a string value
   2. it cannot be null
   
   So this condition can be simplified to 
   if (!meta.consistentId().equals(nodeConsistentId))

##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteSnapshotManager.java
##########
@@ -1750,6 +1768,53 @@ static void copy(FileIOFactory factory, File from, File to, long length) {
         return new IgniteFutureImpl<>(cctx.kernalContext().task().execute(taskCls, snpName));
     }
 
+    /**
+     * Snapshots view supplier.
+     *
+     * @param filter Filter.
+     */
+    private Iterable<SnapshotView> snapshotViewSupplier(Map<String, Object> filter) {
+        List<String> snapshotNames = localSnapshotNames();
+
+        String snapshotName = (String)filter.get(SnapshotViewWalker.SNAPSHOT_NAME_FILTER);
+        String nodeConsistentId = (String)filter.get(SnapshotViewWalker.NODE_CONSISTENT_ID_FILTER);
+
+        return F.flat(F.iterator(snapshotNames, snpName -> {
+                if (snapshotName != null && !snapshotName.equals(snpName))
+                    return Collections.emptyList();
+
+                return F.flat(F.iterator(readSnapshotMetadatas(snpName), meta -> {
+                        if (nodeConsistentId != null && !nodeConsistentId.equals(toStringSafe(meta.consistentId())))
+                            return Collections.emptyList();
+
+                        return F.iterator(getCacheGroupsName(meta), cacheGrp -> new SnapshotView(

Review comment:
       Can we use IgniteSnapshotManager#snapshotCacheDirectories (or FilePageStoreManager#cacheDirectories) instead of involving new method?

##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteSnapshotManager.java
##########
@@ -1750,6 +1768,53 @@ static void copy(FileIOFactory factory, File from, File to, long length) {
         return new IgniteFutureImpl<>(cctx.kernalContext().task().execute(taskCls, snpName));
     }
 
+    /**
+     * Snapshots view supplier.
+     *
+     * @param filter Filter.
+     */
+    private Iterable<SnapshotView> snapshotViewSupplier(Map<String, Object> filter) {
+        List<String> snapshotNames = localSnapshotNames();
+
+        String snapshotName = (String)filter.get(SnapshotViewWalker.SNAPSHOT_NAME_FILTER);
+        String nodeConsistentId = (String)filter.get(SnapshotViewWalker.NODE_CONSISTENT_ID_FILTER);
+
+        return F.flat(F.iterator(snapshotNames, snpName -> {
+                if (snapshotName != null && !snapshotName.equals(snpName))
+                    return Collections.emptyList();
+
+                return F.flat(F.iterator(readSnapshotMetadatas(snpName), meta -> {
+                        if (nodeConsistentId != null && !nodeConsistentId.equals(toStringSafe(meta.consistentId())))
+                            return Collections.emptyList();
+
+                        return F.iterator(getCacheGroupsName(meta), cacheGrp -> new SnapshotView(
+                            meta.snapshotName(),
+                            meta.consistentId(),
+                            cacheGrp,
+                            meta.partitions().get(CU.cacheId(cacheGrp))
+                        ), true);
+                    }, true));
+            }, true));
+    }
+
+    /** */
+    private List<String> getCacheGroupsName(SnapshotMetadata meta) {
+        Path path = Paths.get(snapshotLocalDir(meta.snapshotName()).toString(), "db", meta.folderName());
+
+        List<String> res = new ArrayList<>();
+
+        try (DirectoryStream<Path> ds = Files.newDirectoryStream(path,
+            pth -> pth.getFileName().toString().startsWith(CACHE_DIR_PREFIX))) {

Review comment:
       And how about shared cache groups (CACHE_GRP_DIR_PREFIX)?

##########
File path: modules/core/src/main/java/org/apache/ignite/spi/systemview/view/SnapshotView.java
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.spi.systemview.view;
+
+import java.util.Set;
+import org.apache.ignite.internal.managers.systemview.walker.Filtrable;
+import org.apache.ignite.internal.managers.systemview.walker.Order;
+import org.jetbrains.annotations.Nullable;
+
+import static org.apache.ignite.internal.util.IgniteUtils.toStringSafe;
+
+/**
+ * Snapshot representation for a {@link SystemView}.
+ */
+public class SnapshotView {
+    /** Snapshot name. */
+    private final String name;
+
+    /** Node consistent id. */
+    private final Object consistentId;

Review comment:
       Is there something preventing us from making consistentId a string? 




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