Skip to content

Commit 0a7a446

Browse files
IGNITE-17635 Fix checkpoint locks count by current thread after lock timeout - Fixes #10239.
Signed-off-by: Aleksey Plekhanov <plehanov.alex@gmail.com> (cherry picked from commit f67fada)
1 parent f26f784 commit 0a7a446

3 files changed

Lines changed: 84 additions & 1 deletion

File tree

modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/checkpoint/CheckpointReadWriteLock.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public boolean tryReadLock(long timeout, TimeUnit unit) throws InterruptedExcept
8484

8585
boolean res = checkpointLock.readLock().tryLock(timeout, unit);
8686

87-
if (ASSERTION_ENABLED)
87+
if (ASSERTION_ENABLED && res)
8888
CHECKPOINT_LOCK_HOLD_COUNT.set(CHECKPOINT_LOCK_HOLD_COUNT.get() + 1);
8989

9090
return res;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.ignite.internal.processors.cache.persistence.db.checkpoint;
19+
20+
import java.util.concurrent.CountDownLatch;
21+
import java.util.concurrent.TimeUnit;
22+
import org.apache.ignite.cluster.ClusterState;
23+
import org.apache.ignite.configuration.DataRegionConfiguration;
24+
import org.apache.ignite.configuration.DataStorageConfiguration;
25+
import org.apache.ignite.configuration.IgniteConfiguration;
26+
import org.apache.ignite.internal.IgniteEx;
27+
import org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager;
28+
import org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointListener;
29+
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
30+
import org.junit.Test;
31+
32+
/**
33+
* Test of CheckpointTimeoutLock.
34+
*/
35+
public class CheckpointTimeoutLockTest extends GridCommonAbstractTest {
36+
/** {@inheritDoc} */
37+
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
38+
return super.getConfiguration(igniteInstanceName).setDataStorageConfiguration(
39+
new DataStorageConfiguration().setDefaultDataRegionConfiguration(
40+
new DataRegionConfiguration().setPersistenceEnabled(true)));
41+
}
42+
43+
/**
44+
* @throws Exception if failed.
45+
*/
46+
@Test
47+
public void testLockIsHeldByThreadAfterTimeout() throws Exception {
48+
IgniteEx ignite = startGrid();
49+
50+
ignite.cluster().state(ClusterState.ACTIVE);
51+
52+
GridCacheDatabaseSharedManager db = dbMgr(ignite);
53+
54+
CountDownLatch latch = new CountDownLatch(1);
55+
56+
db.addCheckpointListener(new CheckpointListener() {
57+
@Override public void onMarkCheckpointBegin(Context ctx) {
58+
latch.countDown();
59+
60+
doSleep(200L);
61+
}
62+
63+
@Override public void onCheckpointBegin(Context ctx) {
64+
// No-op.
65+
}
66+
67+
@Override public void beforeCheckpointBegin(Context ctx) {
68+
// No-op.
69+
}
70+
});
71+
72+
db.forceCheckpoint("lock");
73+
74+
latch.await(getTestTimeout(), TimeUnit.MILLISECONDS);
75+
76+
db.checkpointReadLockTimeout(10L);
77+
db.checkpointReadLock();
78+
db.checkpointReadUnlock();
79+
assertFalse(db.checkpointLockIsHeldByThread());
80+
}
81+
}

modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import org.apache.ignite.internal.processors.cache.persistence.db.checkpoint.CheckpointFreeListTest;
4949
import org.apache.ignite.internal.processors.cache.persistence.db.checkpoint.CheckpointListenerForRegionTest;
5050
import org.apache.ignite.internal.processors.cache.persistence.db.checkpoint.CheckpointStartLoggingTest;
51+
import org.apache.ignite.internal.processors.cache.persistence.db.checkpoint.CheckpointTimeoutLockTest;
5152
import org.apache.ignite.internal.processors.cache.persistence.db.checkpoint.IgniteCheckpointDirtyPagesForLowLoadTest;
5253
import org.apache.ignite.internal.processors.cache.persistence.db.checkpoint.LightweightCheckpointTest;
5354
import org.apache.ignite.internal.processors.cache.persistence.db.filename.IgniteUidAsConsistentIdMigrationTest;
@@ -171,6 +172,7 @@ public static void addRealPageStoreTests(List<Class<?>> suite, Collection<Class>
171172
GridTestUtils.addTestIfNeeded(suite, CheckpointListenerForRegionTest.class, ignoredTests);
172173
GridTestUtils.addTestIfNeeded(suite, LightweightCheckpointTest.class, ignoredTests);
173174
GridTestUtils.addTestIfNeeded(suite, CheckpointStartLoggingTest.class, ignoredTests);
175+
GridTestUtils.addTestIfNeeded(suite, CheckpointTimeoutLockTest.class, ignoredTests);
174176
GridTestUtils.addTestIfNeeded(suite, FreeListCachingTest.class, ignoredTests);
175177
GridTestUtils.addTestIfNeeded(suite, IgniteWalIteratorSwitchSegmentTest.class, ignoredTests);
176178
GridTestUtils.addTestIfNeeded(suite, IgniteWalIteratorExceptionDuringReadTest.class, ignoredTests);

0 commit comments

Comments
 (0)