Skip to content

Commit 4df74d9

Browse files
committed
IGNITE-17675 Fixed file resources leak on cluster deactivation/stop in case non full sync WAL mode. (#10250)
(cherry picked from commit 80398bc)
1 parent a5fae73 commit 4df74d9

3 files changed

Lines changed: 136 additions & 1 deletion

File tree

modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/filehandle/FileWriteHandleImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,10 @@ private static void fsync(MappedByteBuffer buf, int off, int len) throws IgniteC
507507
lastFsyncPos = written;
508508
}
509509

510-
walWriter.close();
510+
if (mmap)
511+
U.closeQuiet(fileIO);
512+
else
513+
walWriter.close();
511514

512515
if (!mmap && !rollOver)
513516
buf.free();
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
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.file;
19+
20+
import java.io.File;
21+
import java.io.IOException;
22+
import java.nio.file.OpenOption;
23+
import java.util.List;
24+
import java.util.concurrent.CopyOnWriteArrayList;
25+
import org.apache.ignite.configuration.DataRegionConfiguration;
26+
import org.apache.ignite.configuration.DataStorageConfiguration;
27+
import org.apache.ignite.configuration.IgniteConfiguration;
28+
import org.apache.ignite.configuration.WALMode;
29+
import org.apache.ignite.internal.IgniteEx;
30+
import org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager;
31+
import org.apache.ignite.internal.processors.cache.persistence.file.FileIO;
32+
import org.apache.ignite.internal.processors.cache.persistence.file.FileIODecorator;
33+
import org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory;
34+
import org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager;
35+
import org.apache.ignite.plugin.AbstractTestPluginProvider;
36+
import org.apache.ignite.plugin.PluginContext;
37+
import org.apache.ignite.testframework.GridTestUtils;
38+
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
39+
import org.jetbrains.annotations.Nullable;
40+
import org.junit.Test;
41+
import org.junit.runner.RunWith;
42+
import org.junit.runners.Parameterized;
43+
44+
/**
45+
* Ckeck that WAL manager closes File IO interfaces.
46+
*/
47+
@RunWith(Parameterized.class)
48+
public class WalFilesCloseTest extends GridCommonAbstractTest {
49+
/** Opened File IO interfaces. */
50+
private final List<FileIO> opened = new CopyOnWriteArrayList<>();
51+
52+
/** */
53+
@Parameterized.Parameter
54+
public WALMode mode;
55+
56+
/** */
57+
@Parameterized.Parameters(name = "mode={0}")
58+
public static Object[] parameters() {
59+
return new Object[] {WALMode.FSYNC, WALMode.LOG_ONLY, WALMode.BACKGROUND};
60+
}
61+
62+
/** {@inheritDoc} */
63+
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
64+
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
65+
66+
cfg.setDataStorageConfiguration(new DataStorageConfiguration()
67+
.setWalMode(mode)
68+
.setDefaultDataRegionConfiguration(
69+
new DataRegionConfiguration()
70+
.setPersistenceEnabled(true)
71+
));
72+
73+
cfg.setPluginProviders(new TestWalManagerProvider());
74+
75+
return cfg;
76+
}
77+
78+
/** {@inheritDoc} */
79+
@Override protected void afterTest() throws Exception {
80+
super.afterTest();
81+
82+
cleanPersistenceDir();
83+
}
84+
85+
/** */
86+
@Test
87+
public void testStartStopServer() throws Exception {
88+
IgniteEx srv = startGrid(0);
89+
90+
srv.close();
91+
92+
assertTrue(opened.isEmpty());
93+
}
94+
95+
/** Test class to track opened file IO interfaces. */
96+
private class TestWalManagerProvider extends AbstractTestPluginProvider {
97+
/** {@inheritDoc} */
98+
@Override public String name() {
99+
return "testPlugin";
100+
}
101+
102+
/** {@inheritDoc} */
103+
@Override public <T> @Nullable T createComponent(PluginContext ctx, Class<T> cls) {
104+
if (!IgniteWriteAheadLogManager.class.equals(cls))
105+
return null;
106+
107+
FileWriteAheadLogManager wal = new FileWriteAheadLogManager(((IgniteEx)ctx.grid()).context());
108+
109+
FileIOFactory delegate = GridTestUtils.getFieldValue(wal, "ioFactory");
110+
111+
wal.setFileIOFactory(new FileIOFactory() {
112+
@Override public FileIO create(File file, OpenOption... modes) throws IOException {
113+
FileIODecorator fileIo = new FileIODecorator(delegate.create(file, modes)) {
114+
@Override public void close() throws IOException {
115+
super.close();
116+
117+
opened.remove(this);
118+
}
119+
};
120+
121+
opened.add(fileIo);
122+
123+
return fileIo;
124+
}
125+
});
126+
127+
return (T)wal;
128+
}
129+
}
130+
}

modules/indexing/src/test/java/org/apache/ignite/testsuites/IgnitePdsWithIndexingCoreTestSuite.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.apache.ignite.internal.processors.cache.persistence.db.file.IgnitePdsNoActualWalHistoryTest;
4343
import org.apache.ignite.internal.processors.cache.persistence.db.file.IgnitePdsThreadInterruptionRandomAccessWalTest;
4444
import org.apache.ignite.internal.processors.cache.persistence.db.file.IgnitePdsThreadInterruptionTest;
45+
import org.apache.ignite.internal.processors.cache.persistence.db.file.WalFilesCloseTest;
4546
import org.apache.ignite.internal.processors.cache.persistence.db.wal.IgniteWalRebalanceTest;
4647
import org.apache.ignite.internal.processors.cache.persistence.db.wal.IgniteWalRecoveryPPCTest;
4748
import org.apache.ignite.internal.processors.cache.persistence.db.wal.IgniteWalRecoveryTest;
@@ -93,6 +94,7 @@
9394
IgnitePdsMarshallerMappingRestoreOnNodeStartTest.class,
9495
IgnitePdsThreadInterruptionTest.class,
9596
IgnitePdsThreadInterruptionRandomAccessWalTest.class,
97+
WalFilesCloseTest.class,
9698
IgnitePdsBinarySortObjectFieldsTest.class,
9799

98100
IgnitePdsCorruptedIndexTest.class,

0 commit comments

Comments
 (0)