rpuch commented on code in PR #907:
URL: https://github.com/apache/ignite-3/pull/907#discussion_r915067225


##########
modules/page-memory/src/main/java/org/apache/ignite/internal/pagememory/persistence/PersistentPageMemory.java:
##########
@@ -2095,6 +2095,7 @@ public Collection<FullPageId> 
beginCheckpoint(CompletableFuture<?> allowToReplac
 
         safeToUpdate.set(true);
 
+        // Less memory and no need for Set features.

Review Comment:
   Yes, `concat()` seems better



##########
modules/page-memory/src/main/java/org/apache/ignite/internal/pagememory/persistence/checkpoint/CheckpointDirtyPages.java:
##########
@@ -0,0 +1,358 @@
+/*
+ * 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.pagememory.persistence.checkpoint;
+
+import static java.util.Collections.binarySearch;
+import static java.util.stream.Collectors.toList;
+import static org.apache.ignite.internal.pagememory.util.PageIdUtils.pageId;
+import static 
org.apache.ignite.internal.pagememory.util.PageIdUtils.partitionId;
+
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import java.util.RandomAccess;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.ignite.internal.pagememory.FullPageId;
+import org.apache.ignite.internal.pagememory.persistence.PersistentPageMemory;
+import org.apache.ignite.lang.IgniteBiTuple;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Sorted dirty pages from data regions that should be checkpointed.
+ *
+ * <p>Dirty pages should be sorted by groupId -> partitionId -> pageIdx.
+ */
+class CheckpointDirtyPages {
+    /** Dirty page comparator. */
+    static final Comparator<FullPageId> DIRTY_PAGE_COMPARATOR = Comparator
+            .comparingInt(FullPageId::groupId)
+            .thenComparingLong(FullPageId::effectivePageId);
+
+    /** Empty checkpoint dirty pages. */
+    static final CheckpointDirtyPages EMPTY = new 
CheckpointDirtyPages(List.of());
+
+    /** Sorted dirty pages from data regions by groupId -> partitionId -> 
pageIdx. */
+    private final List<IgniteBiTuple<PersistentPageMemory, List<FullPageId>>> 
dirtyPages;
+
+    /** Total number of dirty pages. */
+    private final int dirtyPagesCount;
+
+    /**
+     * Constructor.
+     *
+     * @param dirtyPages Sorted dirty pages from data regions by groupId -> 
partitionId -> pageIdx.
+     */
+    public CheckpointDirtyPages(Map<PersistentPageMemory, List<FullPageId>> 
dirtyPages) {
+        this(dirtyPages.isEmpty() ? List.of()
+                : dirtyPages.entrySet().stream().map(e -> new 
IgniteBiTuple<>(e.getKey(), e.getValue())).collect(toList()));
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param dirtyPages Sorted dirty pages from data regions by groupId -> 
partitionId -> pageIdx.
+     */
+    public CheckpointDirtyPages(List<IgniteBiTuple<PersistentPageMemory, 
List<FullPageId>>> dirtyPages) {
+        assert dirtyPages instanceof RandomAccess : dirtyPages;
+
+        this.dirtyPages = dirtyPages;
+
+        int count = 0;
+
+        for (IgniteBiTuple<PersistentPageMemory, List<FullPageId>> pages : 
dirtyPages) {
+            assert !pages.getValue().isEmpty() : pages.getKey();
+            assert pages.getValue() instanceof RandomAccess : pages.getValue();
+
+            count += pages.getValue().size();
+        }
+
+        dirtyPagesCount = count;
+    }
+
+    /**
+     * Returns total number of dirty pages.
+     */
+    public int dirtyPagesCount() {
+        return dirtyPagesCount;
+    }
+
+    /**
+     * Returns a queue of dirty pages to be written to a checkpoint.
+     */
+    public CheckpointDirtyPagesQueue toQueue() {
+        return new CheckpointDirtyPagesQueue();
+    }
+
+    /**
+     * Looks for dirty page views for a specific group and partition.
+     *
+     * @param grpId Group ID.
+     * @param partId Partition ID.
+     */
+    public @Nullable CheckpointDirtyPagesView findView(int grpId, int partId) {
+        if (dirtyPages.isEmpty()) {
+            return null;
+        }
+
+        FullPageId startPageId = new FullPageId(pageId(partId, (byte) 0, 0), 
grpId);
+        FullPageId endPageId = new FullPageId(pageId(partId + 1, (byte) 0, 0), 
grpId);
+
+        for (int i = 0; i < dirtyPages.size(); i++) {
+            List<FullPageId> pageIds = dirtyPages.get(i).getValue();
+
+            int fromIndex = binarySearch(pageIds, startPageId, 
DIRTY_PAGE_COMPARATOR);
+
+            fromIndex = fromIndex >= 0 ? fromIndex : Math.min(pageIds.size() - 
1, -fromIndex - 1);
+
+            if (!equalsByGroupAndPartition(startPageId, 
pageIds.get(fromIndex))) {
+                continue;
+            }
+
+            int toIndex = binarySearch(pageIds.subList(fromIndex, 
pageIds.size()), endPageId, DIRTY_PAGE_COMPARATOR);
+
+            toIndex = toIndex > 0 ? toIndex - 1 : -toIndex - 2;

Review Comment:
   Yes, thanks!



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