You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "NSAmelchev (via GitHub)" <gi...@apache.org> on 2026/10/20 08:42:55 UTC

[PR] IGNITE-29175 Copy compressed snapshot partitions sparsely on restore instead of punching holes [ignite]

NSAmelchev opened a new pull request, #13710:
URL: https://github.com/apache/ignite/pull/13710

   Before: a local partition of a compressed group was copied densely with `transferTo`, so the holes
   of the sparse snapshot file became zeros on disk. Then the copy was opened as a `FilePageStore`,
   every page was read again and a hole was punched after the compressed bytes of each page with a
   separate `fallocate` call.
   
   Now: the partition is copied page by page. The compressed size is taken from the page header and
   only these bytes are written at the page offset, so the file system leaves the rest of the page
   unallocated and the copy is sparse without the second pass. Uncompressed pages are written whole.
   The snapshot is opened read-only, as for uncompressed groups. Partitions received from remote nodes
   are written by the file receiver and are punched as before.
   
   Disk Page Compressions 4 (TEST_SCALE_FACTOR=1.0, 4-CPU agents): 37:42 on master vs 28:44.


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


Re: [PR] IGNITE-29175 Copy compressed snapshot partitions sparsely on restore instead of punching holes [ignite]

Posted by "Vladsz83 (via GitHub) via notifications" <no...@ignite.apache.org>.
Vladsz83 commented on code in PR #13710:
URL: https://github.com/apache/ignite/pull/13710#discussion_r4454598988


##########
modules/compress/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotCompressionRestoreSizeTest.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.internal.processors.cache.persistence.snapshot;
+
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.DiskPageCompression;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.metric.MetricRegistry;
+import org.apache.ignite.spi.metric.LongMetric;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+import static org.apache.ignite.internal.processors.cache.CacheGroupMetricsImpl.CACHE_GROUP_METRICS_PREFIX;
+import static org.apache.ignite.internal.processors.cache.persistence.snapshot.AbstractSnapshotSelfTest.SNAPSHOT_NAME;
+import static org.apache.ignite.internal.processors.metric.impl.MetricUtils.metricName;
+
+/** Checks the disk space of a compressed cache group restored from a snapshot. */
+public class SnapshotCompressionRestoreSizeTest extends GridCommonAbstractTest {

Review Comment:
   We could use `assumeFalse` or `assumeTrue` to reduce duplicated runs. Or we could take other existing test.



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


Re: [PR] IGNITE-29175 Copy compressed snapshot partitions sparsely on restore instead of punching holes [ignite]

Posted by "NSAmelchev (via GitHub) via notifications" <no...@ignite.apache.org>.
NSAmelchev commented on code in PR #13710:
URL: https://github.com/apache/ignite/pull/13710#discussion_r4453856607


##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotRestoreProcess.java:
##########
@@ -1796,6 +1797,13 @@ private void copyCompressed(SnapshotRestoreContext opCtx, int grpId, File from,
         int pageSize = ctx.cache().context().database().pageSize();
 
         try (FileIO src = ioFactory.create(from, READ); FileIO dest = ioFactory.create(to, CREATE, WRITE)) {
+            long len = src.size();
+
+            // XFS preallocates blocks on extending writes, and those between the pages would stay allocated.

Review Comment:
   Reworded: the file gets its final size first, so the page writes below don’t extend it. Otherwise XFS preallocates blocks on extending writes, and those between the pages stay allocated (see “speculative preallocation” in the XFS FAQ, linked from the comment).



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


Re: [PR] IGNITE-29175 Copy compressed snapshot partitions sparsely on restore instead of punching holes [ignite]

Posted by "NSAmelchev (via GitHub) via notifications" <no...@ignite.apache.org>.
NSAmelchev merged PR #13710:
URL: https://github.com/apache/ignite/pull/13710


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


Re: [PR] IGNITE-29175 Copy compressed snapshot partitions sparsely on restore instead of punching holes [ignite]

Posted by "NSAmelchev (via GitHub) via notifications" <no...@ignite.apache.org>.
NSAmelchev commented on code in PR #13710:
URL: https://github.com/apache/ignite/pull/13710#discussion_r4453866322


##########
modules/compress/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotCompressionRestoreSizeTest.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.internal.processors.cache.persistence.snapshot;
+
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.DiskPageCompression;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.metric.MetricRegistry;
+import org.apache.ignite.spi.metric.LongMetric;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+import static org.apache.ignite.internal.processors.cache.CacheGroupMetricsImpl.CACHE_GROUP_METRICS_PREFIX;
+import static org.apache.ignite.internal.processors.cache.persistence.snapshot.AbstractSnapshotSelfTest.SNAPSHOT_NAME;
+import static org.apache.ignite.internal.processors.metric.impl.MetricUtils.metricName;
+
+/** Checks the disk space of a compressed cache group restored from a snapshot. */
+public class SnapshotCompressionRestoreSizeTest extends GridCommonAbstractTest {

Review Comment:
   I’d keep it separate. SnapshotCompressionBasicTest is parameterized by onlyPrimary, which makes no difference for a single node, so the test would run twice. Its fixture also builds a three-node snapshot the test doesn’t need and keeps the snapshot directory between the runs, so the test would need its own snapshot name and cleanup. The whole class, including the node start, takes about three seconds.



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


Re: [PR] IGNITE-29175 Copy compressed snapshot partitions sparsely on restore instead of punching holes [ignite]

Posted by "NSAmelchev (via GitHub) via notifications" <no...@ignite.apache.org>.
NSAmelchev commented on code in PR #13710:
URL: https://github.com/apache/ignite/pull/13710#discussion_r4453873621


##########
modules/compress/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotCompressionRestoreSizeTest.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.internal.processors.cache.persistence.snapshot;
+
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.DiskPageCompression;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.metric.MetricRegistry;
+import org.apache.ignite.spi.metric.LongMetric;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+import static org.apache.ignite.internal.processors.cache.CacheGroupMetricsImpl.CACHE_GROUP_METRICS_PREFIX;
+import static org.apache.ignite.internal.processors.cache.persistence.snapshot.AbstractSnapshotSelfTest.SNAPSHOT_NAME;
+import static org.apache.ignite.internal.processors.metric.impl.MetricUtils.metricName;
+
+/** Checks the disk space of a compressed cache group restored from a snapshot. */
+public class SnapshotCompressionRestoreSizeTest extends GridCommonAbstractTest {
+    /** Makes partition files much larger than 64 KiB: XFS doesn't preallocate blocks for smaller ones. */

Review Comment:
   The test isn’t XFS-specific: it checks that restored partitions are sparse on any file system. XFS is the one known to break the sparse copy, and it preallocates only for files above 64 KiB, so with small partitions the test would pass even without the fix. Reworded the comment.



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


Re: [PR] IGNITE-29175 Copy compressed snapshot partitions sparsely on restore instead of punching holes [ignite]

Posted by "Vladsz83 (via GitHub) via notifications" <no...@ignite.apache.org>.
Vladsz83 commented on code in PR #13710:
URL: https://github.com/apache/ignite/pull/13710#discussion_r4454598988


##########
modules/compress/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotCompressionRestoreSizeTest.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.internal.processors.cache.persistence.snapshot;
+
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.DiskPageCompression;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.metric.MetricRegistry;
+import org.apache.ignite.spi.metric.LongMetric;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+import static org.apache.ignite.internal.processors.cache.CacheGroupMetricsImpl.CACHE_GROUP_METRICS_PREFIX;
+import static org.apache.ignite.internal.processors.cache.persistence.snapshot.AbstractSnapshotSelfTest.SNAPSHOT_NAME;
+import static org.apache.ignite.internal.processors.metric.impl.MetricUtils.metricName;
+
+/** Checks the disk space of a compressed cache group restored from a snapshot. */
+public class SnapshotCompressionRestoreSizeTest extends GridCommonAbstractTest {

Review Comment:
   We could use `assumeFalse` or `assumeTrue` to reduce duplicated runs. Or we could take otehr existing test.



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


Re: [PR] IGNITE-29175 Copy compressed snapshot partitions sparsely on restore instead of punching holes [ignite]

Posted by "NSAmelchev (via GitHub) via notifications" <no...@ignite.apache.org>.
NSAmelchev commented on code in PR #13710:
URL: https://github.com/apache/ignite/pull/13710#discussion_r4445539848


##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotRestoreProcess.java:
##########
@@ -1797,6 +1786,52 @@ private void copyLocalAsync(
             });
     }
 
+    /**
+     * Copies a partition of a compressed cache group page by page writing only the compressed bytes of each page, so the
+     * rest of the page is left unallocated by the file system and the copy is sparse without punching holes in it.
+     */
+    private void copyCompressed(SnapshotRestoreContext opCtx, int grpId, File from, File to) {
+        FileIOFactory ioFactory = ctx.cache().context().snapshotMgr().ioFactory();
+        FilePageStoreManager storeMgr = (FilePageStoreManager)ctx.cache().context().pageStore();
+        int pageSize = ctx.cache().context().database().pageSize();
+
+        try (FileIO src = ioFactory.create(from, READ); FileIO dest = ioFactory.create(to, CREATE, WRITE)) {
+            ByteBuffer buf = locBuff.get();
+
+            buf.clear();
+            src.readFully(buf, 0);
+            buf.flip();
+
+            buf.getLong(); // Signature.
+
+            int hdrSize = storeMgr.getPageStoreFactory(grpId, null).headerSize(buf.getInt());
+
+            buf.rewind();
+            buf.limit(hdrSize);
+            dest.writeFully(buf, 0);
+
+            for (long off = hdrSize, len = src.size(); off < len; off += pageSize) {
+                if (opCtx.stopChecker.getAsBoolean())
+                    throw new IgniteInterruptedException("The operation has been stopped on copy file: " + from.getAbsolutePath());
+
+                if (Thread.interrupted())
+                    throw new IgniteInterruptedException("Thread has been interrupted: " + Thread.currentThread().getName());
+
+                buf.clear();
+                src.readFully(buf, off);
+                buf.flip();
+
+                if (PageIO.getCompressionType(buf) != CompressionProcessor.UNCOMPRESSED_PAGE)
+                    buf.limit(PageIO.getCompressedSize(buf));
+
+                dest.writeFully(buf, off);
+            }
+        }
+        catch (IOException e) {
+            throw new IgniteException(e);
+        }
+    }
+
     /** */
     private void punchHole(int grpId, int partId, File partFile) throws Exception {

Review Comment:
   Yes, the remote path still copies densely and punches afterwards, but I’d keep that out of this PR. FileReceiver works at the transport level: it calls transferFrom and knows nothing about pages. Compressed pages aren’t zero-filled either, only their tails are, so the receiver would have to parse page headers or scan every block in user space instead of using transferFrom. That needs its own ticket and measurement.



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


Re: [PR] IGNITE-29175 Copy compressed snapshot partitions sparsely on restore instead of punching holes [ignite]

Posted by "Vladsz83 (via GitHub) via notifications" <no...@ignite.apache.org>.
Vladsz83 commented on code in PR #13710:
URL: https://github.com/apache/ignite/pull/13710#discussion_r4452391717


##########
modules/compress/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotCompressionRestoreSizeTest.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.internal.processors.cache.persistence.snapshot;
+
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.DiskPageCompression;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.metric.MetricRegistry;
+import org.apache.ignite.spi.metric.LongMetric;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+import static org.apache.ignite.internal.processors.cache.CacheGroupMetricsImpl.CACHE_GROUP_METRICS_PREFIX;
+import static org.apache.ignite.internal.processors.cache.persistence.snapshot.AbstractSnapshotSelfTest.SNAPSHOT_NAME;
+import static org.apache.ignite.internal.processors.metric.impl.MetricUtils.metricName;
+
+/** Checks the disk space of a compressed cache group restored from a snapshot. */
+public class SnapshotCompressionRestoreSizeTest extends GridCommonAbstractTest {

Review Comment:
   Launching a test class takes some time and prolongs the tests. Here we have a single real test. Can we put it into an existing test class like SnapshotCompressionBasicTest?



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotRestoreProcess.java:
##########
@@ -1796,6 +1797,13 @@ private void copyCompressed(SnapshotRestoreContext opCtx, int grpId, File from,
         int pageSize = ctx.cache().context().database().pageSize();
 
         try (FileIO src = ioFactory.create(from, READ); FileIO dest = ioFactory.create(to, CREATE, WRITE)) {
+            long len = src.size();
+
+            // XFS preallocates blocks on extending writes, and those between the pages would stay allocated.

Review Comment:
   To me, doesn't tell why we do it here.



##########
modules/compress/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotCompressionRestoreSizeTest.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.internal.processors.cache.persistence.snapshot;
+
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.DiskPageCompression;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.metric.MetricRegistry;
+import org.apache.ignite.spi.metric.LongMetric;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+import static org.apache.ignite.internal.processors.cache.CacheGroupMetricsImpl.CACHE_GROUP_METRICS_PREFIX;
+import static org.apache.ignite.internal.processors.cache.persistence.snapshot.AbstractSnapshotSelfTest.SNAPSHOT_NAME;
+import static org.apache.ignite.internal.processors.metric.impl.MetricUtils.metricName;
+
+/** Checks the disk space of a compressed cache group restored from a snapshot. */
+public class SnapshotCompressionRestoreSizeTest extends GridCommonAbstractTest {
+    /** Makes partition files much larger than 64 KiB: XFS doesn't preallocate blocks for smaller ones. */
+    private static final int KEYS = 4_000;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+        return super.getConfiguration(igniteInstanceName).setDataStorageConfiguration(new DataStorageConfiguration()
+            .setPageSize(8 * 1024)
+            .setDefaultDataRegionConfiguration(new DataRegionConfiguration().setPersistenceEnabled(true)));
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        cleanPersistenceDir();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+
+        cleanPersistenceDir();
+    }
+
+    /** */
+    @Test
+    public void testRestoredPartitionsAreSparse() throws Exception {
+        IgniteEx ignite = startGrid(0);
+
+        ignite.cluster().state(ClusterState.ACTIVE);
+
+        IgniteCache<Integer, byte[]> cache = ignite.createCache(new CacheConfiguration<Integer, byte[]>(DEFAULT_CACHE_NAME)
+            .setAffinity(new RendezvousAffinityFunction(false, 4))
+            .setDiskPageCompression(DiskPageCompression.SNAPPY));
+
+        for (int i = 0; i < KEYS; i++)
+            cache.put(i, new byte[1024]);
+
+        ignite.snapshot().createSnapshot(SNAPSHOT_NAME).get();
+
+        cache.destroy();
+
+        ignite.snapshot().restoreSnapshot(SNAPSHOT_NAME, null).get();
+
+        MetricRegistry mreg = ignite.context().metric().registry(metricName(CACHE_GROUP_METRICS_PREFIX, DEFAULT_CACHE_NAME));
+
+        long size = mreg.<LongMetric>findMetric("StorageSize").value();
+        long sparseSize = mreg.<LongMetric>findMetric("SparseStorageSize").value();
+
+        assertTrue("sparseSize=" + sparseSize + ", size=" + size, sparseSize < 0.75 * size);

Review Comment:
   Why exactly '0.75'?  `sparseSize < size` is enough to me.



##########
modules/compress/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotCompressionRestoreSizeTest.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.internal.processors.cache.persistence.snapshot;
+
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.DiskPageCompression;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.metric.MetricRegistry;
+import org.apache.ignite.spi.metric.LongMetric;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+import static org.apache.ignite.internal.processors.cache.CacheGroupMetricsImpl.CACHE_GROUP_METRICS_PREFIX;
+import static org.apache.ignite.internal.processors.cache.persistence.snapshot.AbstractSnapshotSelfTest.SNAPSHOT_NAME;
+import static org.apache.ignite.internal.processors.metric.impl.MetricUtils.metricName;
+
+/** Checks the disk space of a compressed cache group restored from a snapshot. */
+public class SnapshotCompressionRestoreSizeTest extends GridCommonAbstractTest {
+    /** Makes partition files much larger than 64 KiB: XFS doesn't preallocate blocks for smaller ones. */

Review Comment:
   Can you, please, clarify why we should avoid the preallocations. Also, we refer to XFS. Is this test dedicated for it? Or we might refer to it as an 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: notifications-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-29175 Copy compressed snapshot partitions sparsely on restore instead of punching holes [ignite]

Posted by "NSAmelchev (via GitHub) via notifications" <no...@ignite.apache.org>.
NSAmelchev commented on code in PR #13710:
URL: https://github.com/apache/ignite/pull/13710#discussion_r4445534351


##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotRestoreProcess.java:
##########
@@ -1797,6 +1786,52 @@ private void copyLocalAsync(
             });
     }
 
+    /**
+     * Copies a partition of a compressed cache group page by page writing only the compressed bytes of each page, so the
+     * rest of the page is left unallocated by the file system and the copy is sparse without punching holes in it.
+     */
+    private void copyCompressed(SnapshotRestoreContext opCtx, int grpId, File from, File to) {
+        FileIOFactory ioFactory = ctx.cache().context().snapshotMgr().ioFactory();
+        FilePageStoreManager storeMgr = (FilePageStoreManager)ctx.cache().context().pageStore();
+        int pageSize = ctx.cache().context().database().pageSize();
+
+        try (FileIO src = ioFactory.create(from, READ); FileIO dest = ioFactory.create(to, CREATE, WRITE)) {
+            ByteBuffer buf = locBuff.get();
+
+            buf.clear();
+            src.readFully(buf, 0);
+            buf.flip();
+
+            buf.getLong(); // Signature.
+
+            int hdrSize = storeMgr.getPageStoreFactory(grpId, null).headerSize(buf.getInt());
+
+            buf.rewind();
+            buf.limit(hdrSize);
+            dest.writeFully(buf, 0);
+
+            for (long off = hdrSize, len = src.size(); off < len; off += pageSize) {
+                if (opCtx.stopChecker.getAsBoolean())
+                    throw new IgniteInterruptedException("The operation has been stopped on copy file: " + from.getAbsolutePath());

Review Comment:
   I’d keep them separate: the same pair of checks is already in copyLocalAsync and punchHole, and each message says what happened: the stopped operation names the file, the interrupt names the thread.



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotRestoreProcess.java:
##########
@@ -1797,6 +1786,52 @@ private void copyLocalAsync(
             });
     }
 
+    /**
+     * Copies a partition of a compressed cache group page by page writing only the compressed bytes of each page, so the
+     * rest of the page is left unallocated by the file system and the copy is sparse without punching holes in it.
+     */
+    private void copyCompressed(SnapshotRestoreContext opCtx, int grpId, File from, File to) {

Review Comment:
   It has one caller, so I’d keep it next to that caller for now. Snapshot creation can’t reuse it as is: sendPart copies a live partition while checkpoints keep writing to it, and the delta fixes the copy afterwards, so a page header read during the copy can’t be trusted. The remote path receives a stream, so it has no pages to iterate over. If either path gets this optimization, moving the method next to copy is a small change.



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


Re: [PR] IGNITE-29175 Copy compressed snapshot partitions sparsely on restore instead of punching holes [ignite]

Posted by "Vladsz83 (via GitHub) via notifications" <no...@ignite.apache.org>.
Vladsz83 commented on code in PR #13710:
URL: https://github.com/apache/ignite/pull/13710#discussion_r4442507061


##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotRestoreProcess.java:
##########
@@ -1797,6 +1786,52 @@ private void copyLocalAsync(
             });
     }
 
+    /**
+     * Copies a partition of a compressed cache group page by page writing only the compressed bytes of each page, so the
+     * rest of the page is left unallocated by the file system and the copy is sparse without punching holes in it.
+     */
+    private void copyCompressed(SnapshotRestoreContext opCtx, int grpId, File from, File to) {
+        FileIOFactory ioFactory = ctx.cache().context().snapshotMgr().ioFactory();
+        FilePageStoreManager storeMgr = (FilePageStoreManager)ctx.cache().context().pageStore();
+        int pageSize = ctx.cache().context().database().pageSize();
+
+        try (FileIO src = ioFactory.create(from, READ); FileIO dest = ioFactory.create(to, CREATE, WRITE)) {
+            ByteBuffer buf = locBuff.get();
+
+            buf.clear();
+            src.readFully(buf, 0);
+            buf.flip();
+
+            buf.getLong(); // Signature.
+
+            int hdrSize = storeMgr.getPageStoreFactory(grpId, null).headerSize(buf.getInt());
+
+            buf.rewind();
+            buf.limit(hdrSize);
+            dest.writeFully(buf, 0);

Review Comment:
   Do we calculate here a proper header size only?



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotRestoreProcess.java:
##########
@@ -1797,6 +1786,52 @@ private void copyLocalAsync(
             });
     }
 
+    /**
+     * Copies a partition of a compressed cache group page by page writing only the compressed bytes of each page, so the
+     * rest of the page is left unallocated by the file system and the copy is sparse without punching holes in it.
+     */
+    private void copyCompressed(SnapshotRestoreContext opCtx, int grpId, File from, File to) {

Review Comment:
   Should we move this knowledge how to properly copy compressed partition inside `IgniteSnapshotManager` to avoid such a duplicated work in future? 



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotRestoreProcess.java:
##########
@@ -1797,6 +1786,52 @@ private void copyLocalAsync(
             });
     }
 
+    /**
+     * Copies a partition of a compressed cache group page by page writing only the compressed bytes of each page, so the
+     * rest of the page is left unallocated by the file system and the copy is sparse without punching holes in it.
+     */
+    private void copyCompressed(SnapshotRestoreContext opCtx, int grpId, File from, File to) {
+        FileIOFactory ioFactory = ctx.cache().context().snapshotMgr().ioFactory();
+        FilePageStoreManager storeMgr = (FilePageStoreManager)ctx.cache().context().pageStore();
+        int pageSize = ctx.cache().context().database().pageSize();
+
+        try (FileIO src = ioFactory.create(from, READ); FileIO dest = ioFactory.create(to, CREATE, WRITE)) {
+            ByteBuffer buf = locBuff.get();
+
+            buf.clear();
+            src.readFully(buf, 0);
+            buf.flip();
+
+            buf.getLong(); // Signature.
+
+            int hdrSize = storeMgr.getPageStoreFactory(grpId, null).headerSize(buf.getInt());
+
+            buf.rewind();
+            buf.limit(hdrSize);
+            dest.writeFully(buf, 0);
+
+            for (long off = hdrSize, len = src.size(); off < len; off += pageSize) {
+                if (opCtx.stopChecker.getAsBoolean())
+                    throw new IgniteInterruptedException("The operation has been stopped on copy file: " + from.getAbsolutePath());

Review Comment:
   Could be combined with Thread.interrupted() like 'stopped or interruped'.



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotRestoreProcess.java:
##########
@@ -1797,6 +1786,52 @@ private void copyLocalAsync(
             });
     }
 
+    /**
+     * Copies a partition of a compressed cache group page by page writing only the compressed bytes of each page, so the
+     * rest of the page is left unallocated by the file system and the copy is sparse without punching holes in it.
+     */
+    private void copyCompressed(SnapshotRestoreContext opCtx, int grpId, File from, File to) {
+        FileIOFactory ioFactory = ctx.cache().context().snapshotMgr().ioFactory();
+        FilePageStoreManager storeMgr = (FilePageStoreManager)ctx.cache().context().pageStore();
+        int pageSize = ctx.cache().context().database().pageSize();
+
+        try (FileIO src = ioFactory.create(from, READ); FileIO dest = ioFactory.create(to, CREATE, WRITE)) {
+            ByteBuffer buf = locBuff.get();
+
+            buf.clear();
+            src.readFully(buf, 0);
+            buf.flip();
+
+            buf.getLong(); // Signature.
+
+            int hdrSize = storeMgr.getPageStoreFactory(grpId, null).headerSize(buf.getInt());
+
+            buf.rewind();
+            buf.limit(hdrSize);
+            dest.writeFully(buf, 0);
+
+            for (long off = hdrSize, len = src.size(); off < len; off += pageSize) {
+                if (opCtx.stopChecker.getAsBoolean())
+                    throw new IgniteInterruptedException("The operation has been stopped on copy file: " + from.getAbsolutePath());
+
+                if (Thread.interrupted())
+                    throw new IgniteInterruptedException("Thread has been interrupted: " + Thread.currentThread().getName());
+
+                buf.clear();
+                src.readFully(buf, off);
+                buf.flip();
+
+                if (PageIO.getCompressionType(buf) != CompressionProcessor.UNCOMPRESSED_PAGE)
+                    buf.limit(PageIO.getCompressedSize(buf));
+
+                dest.writeFully(buf, off);
+            }
+        }
+        catch (IOException e) {
+            throw new IgniteException(e);
+        }
+    }
+
     /** */
     private void punchHole(int grpId, int partId, File partFile) throws Exception {

Review Comment:
   It looks like we have a similar copy path when receiving a partition from a remote node. Should we skip zero-filled pages on the fly there too, so the resulting file stays sparse?



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotRestoreProcess.java:
##########
@@ -1797,6 +1786,52 @@ private void copyLocalAsync(
             });
     }
 
+    /**
+     * Copies a partition of a compressed cache group page by page writing only the compressed bytes of each page, so the
+     * rest of the page is left unallocated by the file system and the copy is sparse without punching holes in it.
+     */
+    private void copyCompressed(SnapshotRestoreContext opCtx, int grpId, File from, File to) {
+        FileIOFactory ioFactory = ctx.cache().context().snapshotMgr().ioFactory();
+        FilePageStoreManager storeMgr = (FilePageStoreManager)ctx.cache().context().pageStore();
+        int pageSize = ctx.cache().context().database().pageSize();
+
+        try (FileIO src = ioFactory.create(from, READ); FileIO dest = ioFactory.create(to, CREATE, WRITE)) {
+            ByteBuffer buf = locBuff.get();
+
+            buf.clear();
+            src.readFully(buf, 0);
+            buf.flip();
+
+            buf.getLong(); // Signature.
+
+            int hdrSize = storeMgr.getPageStoreFactory(grpId, null).headerSize(buf.getInt());
+
+            buf.rewind();
+            buf.limit(hdrSize);
+            dest.writeFully(buf, 0);
+
+            for (long off = hdrSize, len = src.size(); off < len; off += pageSize) {
+                if (opCtx.stopChecker.getAsBoolean())
+                    throw new IgniteInterruptedException("The operation has been stopped on copy file: " + from.getAbsolutePath());
+
+                if (Thread.interrupted())
+                    throw new IgniteInterruptedException("Thread has been interrupted: " + Thread.currentThread().getName());
+
+                buf.clear();
+                src.readFully(buf, off);
+                buf.flip();
+
+                if (PageIO.getCompressionType(buf) != CompressionProcessor.UNCOMPRESSED_PAGE)
+                    buf.limit(PageIO.getCompressedSize(buf));

Review Comment:
   Does this guarantee that free space is available as we iterate over pages with actual `pageSize` step? Should we reuse punchHole()? 



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


Re: [PR] IGNITE-29175 Copy compressed snapshot partitions sparsely on restore instead of punching holes [ignite]

Posted by "NSAmelchev (via GitHub) via notifications" <no...@ignite.apache.org>.
NSAmelchev commented on code in PR #13710:
URL: https://github.com/apache/ignite/pull/13710#discussion_r4453870769


##########
modules/compress/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotCompressionRestoreSizeTest.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.internal.processors.cache.persistence.snapshot;
+
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.DiskPageCompression;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.metric.MetricRegistry;
+import org.apache.ignite.spi.metric.LongMetric;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+import static org.apache.ignite.internal.processors.cache.CacheGroupMetricsImpl.CACHE_GROUP_METRICS_PREFIX;
+import static org.apache.ignite.internal.processors.cache.persistence.snapshot.AbstractSnapshotSelfTest.SNAPSHOT_NAME;
+import static org.apache.ignite.internal.processors.metric.impl.MetricUtils.metricName;
+
+/** Checks the disk space of a compressed cache group restored from a snapshot. */
+public class SnapshotCompressionRestoreSizeTest extends GridCommonAbstractTest {
+    /** Makes partition files much larger than 64 KiB: XFS doesn't preallocate blocks for smaller ones. */
+    private static final int KEYS = 4_000;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+        return super.getConfiguration(igniteInstanceName).setDataStorageConfiguration(new DataStorageConfiguration()
+            .setPageSize(8 * 1024)
+            .setDefaultDataRegionConfiguration(new DataRegionConfiguration().setPersistenceEnabled(true)));
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        cleanPersistenceDir();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+
+        cleanPersistenceDir();
+    }
+
+    /** */
+    @Test
+    public void testRestoredPartitionsAreSparse() throws Exception {
+        IgniteEx ignite = startGrid(0);
+
+        ignite.cluster().state(ClusterState.ACTIVE);
+
+        IgniteCache<Integer, byte[]> cache = ignite.createCache(new CacheConfiguration<Integer, byte[]>(DEFAULT_CACHE_NAME)
+            .setAffinity(new RendezvousAffinityFunction(false, 4))
+            .setDiskPageCompression(DiskPageCompression.SNAPPY));
+
+        for (int i = 0; i < KEYS; i++)
+            cache.put(i, new byte[1024]);
+
+        ignite.snapshot().createSnapshot(SNAPSHOT_NAME).get();
+
+        cache.destroy();
+
+        ignite.snapshot().restoreSnapshot(SNAPSHOT_NAME, null).get();
+
+        MetricRegistry mreg = ignite.context().metric().registry(metricName(CACHE_GROUP_METRICS_PREFIX, DEFAULT_CACHE_NAME));
+
+        long size = mreg.<LongMetric>findMetric("StorageSize").value();
+        long sparseSize = mreg.<LongMetric>findMetric("SparseStorageSize").value();
+
+        assertTrue("sparseSize=" + sparseSize + ", size=" + size, sparseSize < 0.75 * size);

Review Comment:
   sparseSize < size wouldn’t catch the regression: without the fix on XFS the restored group took 0.975 of its logical size (4993024 of 5120322 bytes). With the fix it takes 0.504: the values are zero-filled, so every 8 KiB page compresses into one of its two 4 KiB blocks. 0.75 sits between the two and is the threshold testRestoreFullSnapshot already uses. Added a comment with the expected ratio.



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


Re: [PR] IGNITE-29175 Copy compressed snapshot partitions sparsely on restore instead of punching holes [ignite]

Posted by "NSAmelchev (via GitHub) via notifications" <no...@ignite.apache.org>.
NSAmelchev commented on code in PR #13710:
URL: https://github.com/apache/ignite/pull/13710#discussion_r4445537670


##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotRestoreProcess.java:
##########
@@ -1797,6 +1786,52 @@ private void copyLocalAsync(
             });
     }
 
+    /**
+     * Copies a partition of a compressed cache group page by page writing only the compressed bytes of each page, so the
+     * rest of the page is left unallocated by the file system and the copy is sparse without punching holes in it.
+     */
+    private void copyCompressed(SnapshotRestoreContext opCtx, int grpId, File from, File to) {
+        FileIOFactory ioFactory = ctx.cache().context().snapshotMgr().ioFactory();
+        FilePageStoreManager storeMgr = (FilePageStoreManager)ctx.cache().context().pageStore();
+        int pageSize = ctx.cache().context().database().pageSize();
+
+        try (FileIO src = ioFactory.create(from, READ); FileIO dest = ioFactory.create(to, CREATE, WRITE)) {
+            ByteBuffer buf = locBuff.get();
+
+            buf.clear();
+            src.readFully(buf, 0);
+            buf.flip();
+
+            buf.getLong(); // Signature.
+
+            int hdrSize = storeMgr.getPageStoreFactory(grpId, null).headerSize(buf.getInt());
+
+            buf.rewind();
+            buf.limit(hdrSize);
+            dest.writeFully(buf, 0);

Review Comment:
   Yes, this block only finds the header size and copies the header as is. The size depends on the page store version stored in the file (V1 or V2). FileVersionCheckingFactory#createPageStore reads the version too, but it opens the file with CREATE, READ and WRITE, which fails on a read-only snapshot. So the version is read here and passed to headerSize()



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotRestoreProcess.java:
##########
@@ -1797,6 +1786,52 @@ private void copyLocalAsync(
             });
     }
 
+    /**
+     * Copies a partition of a compressed cache group page by page writing only the compressed bytes of each page, so the
+     * rest of the page is left unallocated by the file system and the copy is sparse without punching holes in it.
+     */
+    private void copyCompressed(SnapshotRestoreContext opCtx, int grpId, File from, File to) {
+        FileIOFactory ioFactory = ctx.cache().context().snapshotMgr().ioFactory();
+        FilePageStoreManager storeMgr = (FilePageStoreManager)ctx.cache().context().pageStore();
+        int pageSize = ctx.cache().context().database().pageSize();
+
+        try (FileIO src = ioFactory.create(from, READ); FileIO dest = ioFactory.create(to, CREATE, WRITE)) {
+            ByteBuffer buf = locBuff.get();
+
+            buf.clear();
+            src.readFully(buf, 0);
+            buf.flip();
+
+            buf.getLong(); // Signature.
+
+            int hdrSize = storeMgr.getPageStoreFactory(grpId, null).headerSize(buf.getInt());
+
+            buf.rewind();
+            buf.limit(hdrSize);
+            dest.writeFully(buf, 0);
+
+            for (long off = hdrSize, len = src.size(); off < len; off += pageSize) {
+                if (opCtx.stopChecker.getAsBoolean())
+                    throw new IgniteInterruptedException("The operation has been stopped on copy file: " + from.getAbsolutePath());
+
+                if (Thread.interrupted())
+                    throw new IgniteInterruptedException("Thread has been interrupted: " + Thread.currentThread().getName());
+
+                buf.clear();
+                src.readFully(buf, off);
+                buf.flip();
+
+                if (PageIO.getCompressionType(buf) != CompressionProcessor.UNCOMPRESSED_PAGE)
+                    buf.limit(PageIO.getCompressedSize(buf));

Review Comment:
   You’re right, skipping bytes doesn’t guarantee holes. On XFS, extending writes trigger speculative preallocation, and the blocks between pages stay allocated: a 100 MiB partition with 50 MiB of compressed data took 100 MiB, even after a remount (see “speculative preallocation” in https://xfs.org/index.php/XFS_FAQ). ext4 isn’t affected. The file now gets its full size before the pages are written, so the writes no longer extend it, and the same file takes 50 MiB on XFS. Calling punchHole() per page gives the same size, but brings back one fallocate per page. Added SnapshotCompressionRestoreSizeTest with partitions large enough to trigger the preallocation: it fails on XFS without the fix.



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