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



##########
File path: 
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteSnapshotManager.java
##########
@@ -1750,6 +1768,43 @@ 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(meta.consistentId()))
+                            return Collections.emptyList();
+
+                    List<String> cacheCrps = snapshotCacheDirectories(snpName, 
meta.folderName()).stream()

Review comment:
       can be simplified to
   ```
   Collection<String> cacheCrps = 
F.viewReadOnly(snapshotCacheDirectories(snpName, meta.folderName(),
       name -> !MetaStorage.METASTORAGE_CACHE_NAME.equals(name)), 
FilePageStoreManager::cacheGroupName);
   ```
   
   btw, should we include metastorage in this view?

##########
File path: 
modules/core/src/main/java/org/apache/ignite/spi/systemview/view/SnapshotView.java
##########
@@ -0,0 +1,87 @@
+/*
+ * 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;
+
+/**
+ * Snapshot representation for a {@link SystemView}.
+ */
+public class SnapshotView {
+    /** Snapshot name. */
+    private final String name;
+
+    /** Node consistent id. */
+    private final String consistentId;
+
+    /** Cache group name. */
+    private final String cacheGrp;
+
+    /** Cache group local partitions. */
+    private final String locPartitions;
+
+    /**
+     * @param name Snapshot name.
+     * @param consistentId Node consistent id.
+     * @param cacheGrp Cache group.
+     * @param locPartitions Cache group local partitions.
+     */
+    public SnapshotView(String name, String consistentId, String cacheGrp, 
@Nullable Set<Integer> locPartitions) {
+        this.name = name;
+        this.consistentId = consistentId;
+        this.cacheGrp = cacheGrp;
+        this.locPartitions = locPartitions != null ? 
String.valueOf(locPartitions) : "[]";

Review comment:
       I think the UX should be improved by replacing `String.valueOf` with 
`S.compact`.
   I also suggest checking this value in the test.

##########
File path: 
modules/core/src/test/java/org/apache/ignite/internal/metric/SystemViewSelfTest.java
##########
@@ -2044,6 +2047,57 @@ public void testBaselineNodeAttributes() throws 
Exception {
         }
     }
 
+    /** */
+    @Test
+    public void testSnapshots() throws Exception {
+        cleanPersistenceDir();
+
+        String dfltCacheGrp = "testGroup";
+
+        String testSnap0 = "testSnap0";
+        String testSnap1 = "testSnap1";
+
+        try (IgniteEx ignite = startGrid(getConfiguration()
+            .setCacheConfiguration(new 
CacheConfiguration<>(DEFAULT_CACHE_NAME).setGroupName(dfltCacheGrp))
+            .setDataStorageConfiguration(
+                new 
DataStorageConfiguration().setDefaultDataRegionConfiguration(
+                    new 
DataRegionConfiguration().setName("pds").setPersistenceEnabled(true)
+                )))
+        ) {
+            ignite.cluster().state(ClusterState.ACTIVE);
+
+            ignite.snapshot().createSnapshot(testSnap0).get();
+
+            SystemView<SnapshotView> views = 
ignite.context().systemView().view(SNAPSHOTS_SYS_VIEW);
+
+            assertEquals(1, F.size(views.iterator()));
+
+            SnapshotView view = views.iterator().next();
+
+            assertEquals(testSnap0, view.snapshotName());
+            assertEquals(dfltCacheGrp, view.cacheGroup());

Review comment:
       I suggest checking local partitions output, too.
   
   something like
   ```
   Collection<Integer> locParts = F.viewReadOnly(
       
ignite.cachex(DEFAULT_CACHE_NAME).context().topology().localPartitions(), 
GridDhtLocalPartition::id);
           
   assertEquals(S.compact(locParts), view.localPartitions());
   ```
   but we should add some values into the cache. I don't think it is worth 
creating 1024 (+1024 in the snapshot) files every time, so it is better to 
limit this number in the cache configuration or add an extra predicate to check 
if partitions were actually created (using IgnitePageStoreManager#exists for 
example).




-- 
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: [email protected]

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


Reply via email to