You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by al...@apache.org on 2025/05/29 13:23:31 UTC

(ignite) branch master updated: IGNITE-17734 Fix freelist corruption in JDK17 with ShenandoahGC and assertions turned off - Fixes #12074.

This is an automated email from the ASF dual-hosted git repository.

alexpl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new b2e7175a4f5 IGNITE-17734 Fix freelist corruption in JDK17 with ShenandoahGC and assertions turned off - Fixes #12074.
b2e7175a4f5 is described below

commit b2e7175a4f522d1f3863b44832a479e3b3751552
Author: Sergey Korotkov <se...@gmail.com>
AuthorDate: Thu May 29 16:18:10 2025 +0300

    IGNITE-17734 Fix freelist corruption in JDK17 with ShenandoahGC and assertions turned off - Fixes #12074.
    
    Signed-off-by: Aleksey Plekhanov <pl...@gmail.com>
---
 .../cache/persistence/freelist/PagesList.java      |   3 +-
 .../database/FreeListCutTailDifferentGcTest.java   | 262 +++++++++++++++++++++
 .../ignite/testsuites/IgniteBasicTestSuite2.java   |   3 +
 3 files changed, 267 insertions(+), 1 deletion(-)

diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/freelist/PagesList.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/freelist/PagesList.java
index 62b2a37cd0c..348ae7ce42f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/freelist/PagesList.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/freelist/PagesList.java
@@ -154,7 +154,8 @@ public abstract class PagesList extends DataStructure {
 
             long tailId = io.getNextId(pageAddr);
 
-            assert tailId != 0;
+            if (tailId == 0)
+                throw corruptedFreeListException("nextId is 0 in non-tail page [pageId=" + U.hexLong(pageId) + "]", pageId);
 
             io.setNextId(pageAddr, 0L);
 
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/FreeListCutTailDifferentGcTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/FreeListCutTailDifferentGcTest.java
new file mode 100644
index 00000000000..e939d317c54
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/FreeListCutTailDifferentGcTest.java
@@ -0,0 +1,262 @@
+/*
+ * 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.database;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.BrokenBarrierException;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.CyclicBarrier;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicBoolean;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteFuture;
+import org.apache.ignite.lang.IgniteFutureTimeoutException;
+import org.apache.ignite.lang.IgniteRunnable;
+import org.apache.ignite.resources.IgniteInstanceResource;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.testframework.CallbackExecutorLogListener;
+import org.apache.ignite.testframework.ListeningTestLogger;
+import org.apache.ignite.testframework.junits.WithSystemProperty;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.testframework.junits.multijvm.IgniteProcessProxy;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import static org.apache.ignite.internal.processors.cache.persistence.freelist.PagesList.IGNITE_PAGES_LIST_STRIPES_PER_BUCKET;
+import static org.apache.ignite.testframework.GridTestUtils.runMultiThreadedAsync;
+
+/**
+ * Test freelists ensuring that the optimization by the C2 Jit compilator was done.
+ */
+@RunWith(Parameterized.class)
+@WithSystemProperty(key = IGNITE_PAGES_LIST_STRIPES_PER_BUCKET, value = "1")
+public class FreeListCutTailDifferentGcTest extends GridCommonAbstractTest {
+    /** */
+    private static final int KEYS_COUNT = 5_000;
+
+    /** Signals once method under test is C2 Jit compiled in server node. */
+    CountDownLatch c2JitCompiled = new CountDownLatch(1);
+
+    /** JVM options to start the server node in remote JVM. */
+    @Parameterized.Parameter
+    public List<String> jvmOpts;
+
+    /** */
+    @Parameterized.Parameters(name = "{0}")
+    public static Iterable<List<String>> params() {
+        ArrayList<List<String>> params = new ArrayList<>(List.of(
+            List.of("-XX:+UseShenandoahGC"),
+            List.of("-XX:+UseShenandoahGC", "-ea"),
+
+            List.of("-XX:+UseG1GC"),
+            List.of("-XX:+UseG1GC", "-ea")
+        ));
+
+        if (Runtime.version().feature() >= 17 || U.isLinux())
+            addZgc(params);
+
+        return params;
+    }
+
+    /**
+     * Ensure that the PagesList$CutTail::run handler is not broken if C2 Jit-compiled.
+     * With various garbage collectors and with assertions both turned on and off.
+     */
+    @Test
+    public void testCutTail() throws Exception {
+        try (Ignite ignite = prepareCluster(jvmOpts,
+            "org.apache.ignite.internal.processors.cache.persistence.freelist.PagesList$CutTail::run")) {
+            IgniteFuture<Void> jobFut = ignite.compute().runAsync(new TestCutTailJob());
+
+            assertTrue(c2JitCompiled.await(getTestTimeout() / 2, TimeUnit.MILLISECONDS));
+
+            try {
+                // Let it work for 2 seconds with the optimized C2 Jit-compiled variant of the
+                // PagesList$CutTail::run method. It's enough to reproduce problem if it is broken.
+                jobFut.get(2000, TimeUnit.MILLISECONDS);
+            }
+            catch (IgniteFutureTimeoutException e) {
+                jobFut.cancel();
+            }
+        }
+    }
+
+    /**
+     * Starts server node in remote JVM with the JVM options passed.
+     * Registers listener to signal once the method passed is C2 Jit-compiled in server node.
+     * Starts client node in local JVM.
+     *
+     * @param jvmOpts JVM options for the server node.
+     * @param method Fully qualified name of method.
+     * @return Client node.
+     */
+    private Ignite prepareCluster(List<String> jvmOpts, String method) throws Exception {
+        CountDownLatch remoteJvmServerStarted = new CountDownLatch(1);
+
+        ListeningTestLogger lsnrLog = new ListeningTestLogger(log);
+
+        lsnrLog.registerListener(new CallbackExecutorLogListener(".*Topology snapshot \\[ver=1,.*",
+            remoteJvmServerStarted::countDown));
+
+        lsnrLog.registerListener(new CallbackExecutorLogListener(
+            ".*Compiled method \\(c2\\).*" + method.replace("$", "\\$") + ".*",
+            c2JitCompiled::countDown));
+
+        IgniteConfiguration cfg = optimize(getConfiguration("remote-jvm-server"));
+
+        new IgniteProcessProxy(cfg, lsnrLog, null, false) {
+            @Override protected Collection<String> filteredJvmArgs() throws Exception {
+                Collection<String> args = super.filteredJvmArgs();
+
+                args.remove("-ea");
+
+                args.add("-XX:+UnlockDiagnosticVMOptions");
+                args.add("-XX:PrintAssemblyOptions=intel");
+                args.add("-XX:CompileCommand=print," + method);
+
+                args.addAll(jvmOpts);
+
+                return args;
+            }
+        };
+
+        remoteJvmServerStarted.await(getTestTimeout(), TimeUnit.MILLISECONDS);
+
+        return startClientGrid("local-jvm-client");
+    }
+
+    /**
+     * Perfrom concurrent updates and deletes ensuring the CutTail called enough
+     * times to invoke the C2 optimizing Jit compiler.
+     */
+    private static class TestCutTailJob implements IgniteRunnable {
+        /** */
+        @IgniteInstanceResource
+        Ignite ignite;
+
+        /** {@inheritDoc} */
+        @Override public void run() {
+            IgniteCache<Object, Object> cache = ignite.createCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME));
+
+            for (int i = 0; i < KEYS_COUNT; i++)
+                cache.put(i, value());
+
+            AtomicBoolean stop = new AtomicBoolean(false);
+
+            CyclicBarrier barrier = new CyclicBarrier(6);
+
+            IgniteInternalFuture<Long> updateFut = runMultiThreadedAsync(() -> {
+                while (!stop.get()) {
+                    try {
+                        barrier.await(100, TimeUnit.MILLISECONDS);
+
+                        cache.put(key(), value());
+                    }
+                    catch (InterruptedException | BrokenBarrierException ignored) {
+                        stop.set(true);
+                    }
+                    catch (TimeoutException ignored) {
+                        // No-op.
+                    }
+                    catch (Exception ex) {
+                        stop.set(true);
+
+                        throw ex;
+                    }
+                }
+            }, 24, "update");
+
+            while (!stop.get())
+                cache.remove(key());
+
+            barrier.reset();
+
+            try {
+                updateFut.get();
+            }
+            catch (IgniteCheckedException e) {
+                throw new RuntimeException(e);
+            }
+        }
+
+        /** */
+        private int key() {
+            return ThreadLocalRandom.current().nextInt(KEYS_COUNT);
+        }
+
+        /** */
+        private byte[] value() {
+            return new byte[ThreadLocalRandom.current().nextInt(12000) + 3000];
+        }
+    }
+
+    /**
+     * Add test parameters for the ZGC garbage collector.
+     */
+    private static void addZgc(ArrayList<List<String>> params) {
+        ArrayList<String> opts = new ArrayList<>();
+
+        if (Runtime.version().feature() < 12)
+            opts.add("-XX:+UnlockExperimentalVMOptions");
+
+        opts.add("-XX:+UseZGC");
+        params.add(new ArrayList<>(opts));
+
+        opts.add("-ea");
+        params.add(new ArrayList<>(opts));
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName)
+            .setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(LOCAL_IP_FINDER));
+
+        DataStorageConfiguration dsCfg = new DataStorageConfiguration();
+
+        int pageSize = dsCfg.getPageSize() == 0 ? DataStorageConfiguration.DFLT_PAGE_SIZE : dsCfg.getPageSize();
+
+        dsCfg.setDefaultDataRegionConfiguration(new DataRegionConfiguration()
+            .setMaxSize(pageSize * 10L * KEYS_COUNT));
+
+        cfg.setDataStorageConfiguration(dsCfg);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        super.afterTest();
+
+        stopAllGrids();
+
+        IgniteProcessProxy.killAll();
+    }
+}
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite2.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite2.java
index ee4c46f09fc..cd14b8c40f2 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite2.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite2.java
@@ -71,6 +71,7 @@ import org.apache.ignite.internal.processors.database.BPlusTreeReuseSelfTest;
 import org.apache.ignite.internal.processors.database.BPlusTreeSelfTest;
 import org.apache.ignite.internal.processors.database.CacheFreeListSelfTest;
 import org.apache.ignite.internal.processors.database.DataRegionMetricsSelfTest;
+import org.apache.ignite.internal.processors.database.FreeListCutTailDifferentGcTest;
 import org.apache.ignite.internal.processors.database.IndexStorageSelfTest;
 import org.apache.ignite.internal.processors.database.SwapPathConstructionSelfTest;
 import org.apache.ignite.internal.processors.failure.FailureProcessorLoggingTest;
@@ -225,6 +226,8 @@ import org.junit.runners.Suite;
 
     ConcurrentMappingFileReadWriteTest.class,
     PeriodicHistogramMetricImplTest.class,
+
+    FreeListCutTailDifferentGcTest.class,
 })
 public class IgniteBasicTestSuite2 {
 }