jt2594838 commented on code in PR #18456:
URL: https://github.com/apache/iotdb/pull/18456#discussion_r3765621493
##########
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/wal/node/ConsensusReqReaderTest.java:
##########
@@ -60,23 +62,70 @@ public class ConsensusReqReaderTest {
private static final String logDirectory =
TestConstant.BASE_OUTPUT_PATH.concat("wal-test");
private static final String devicePath = "root.test_sg.test_d";
private WALMode prevMode;
+ private boolean prevWalFileListCacheEnabled;
private WALNode walNode;
@Before
public void setUp() throws Exception {
EnvironmentUtils.cleanDir(logDirectory);
prevMode = config.getWalMode();
+ prevWalFileListCacheEnabled = config.isWalFileListCacheEnabled();
config.setWalMode(WALMode.SYNC);
+ config.setWalFileListCacheEnabled(true);
walNode = new WALNode(identifier, logDirectory);
}
@After
public void tearDown() throws Exception {
walNode.close();
config.setWalMode(prevMode);
+ config.setWalFileListCacheEnabled(prevWalFileListCacheEnabled);
EnvironmentUtils.cleanDir(logDirectory);
}
+ /** Verifies that reader access publishes an incrementally maintained file
snapshot. */
+ @Test
+ public void testIncrementallyUpdateCachedWalFilesAfterRoll() throws
IOException {
Review Comment:
Exercises reader-triggered lazy publication after successive WAL rolls and
uses an external sentinel file to prove the cache is incrementally maintained
instead of rescanning the directory.
##########
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/wal/node/WALFileListCachePerformanceTest.java:
##########
@@ -0,0 +1,338 @@
+/*
+ * 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.iotdb.db.storageengine.dataregion.wal.node;
+
+import org.apache.iotdb.db.conf.IoTDBConfig;
+import org.apache.iotdb.db.conf.IoTDBDescriptor;
+import org.apache.iotdb.db.storageengine.dataregion.wal.utils.WALFileStatus;
+import org.apache.iotdb.db.storageengine.dataregion.wal.utils.WALFileUtils;
+import org.apache.iotdb.db.utils.EnvironmentUtils;
+import org.apache.iotdb.db.utils.constant.TestConstant;
+
+import com.sun.management.HotSpotDiagnosticMXBean;
+import org.apache.tsfile.utils.RamUsageEstimator;
+import org.junit.Assert;
+import org.junit.Assume;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.management.ManagementFactory;
+import java.util.Arrays;
+import java.util.Locale;
+import java.util.TreeMap;
+
+public class WALFileListCachePerformanceTest {
+
+ private static final String ENABLED_PROPERTY =
"iotdb.wal.file-list-cache.perf.enabled";
+ private static final String FILE_COUNTS_PROPERTY =
"iotdb.wal.file-list-cache.perf.file-counts";
+ private static final String WARMUP_READS_PROPERTY =
"iotdb.wal.file-list-cache.perf.warmup-reads";
+ private static final String READS_PROPERTY =
"iotdb.wal.file-list-cache.perf.reads";
+ private static final String ROUNDS_PROPERTY =
"iotdb.wal.file-list-cache.perf.rounds";
+
+ private static final String BASE_DIRECTORY =
+ TestConstant.BASE_OUTPUT_PATH.concat("wal-file-list-cache-performance");
+ private static final int[] DEFAULT_FILE_COUNTS = {1, 10, 100, 1000};
+
+ private static final IoTDBConfig CONFIG =
IoTDBDescriptor.getInstance().getConfig();
+
+ private static final long TREE_MAP_ENTRY_SHALLOW_SIZE =
getTreeMapEntryShallowSize();
+ private static final long FILE_SHALLOW_SIZE =
RamUsageEstimator.shallowSizeOfInstance(File.class);
+ private static final long LONG_SHALLOW_SIZE =
RamUsageEstimator.shallowSizeOfInstance(Long.class);
+ private static final long STRING_SHALLOW_SIZE =
+ RamUsageEstimator.shallowSizeOfInstance(String.class);
+ private static final boolean COMPACT_STRINGS_ENABLED =
isCompactStringsEnabled();
+
+ private static volatile long benchmarkBlackhole;
+
+ /**
+ * Compares repeated sorted-WAL-file reads with the cache disabled and
enabled for increasing
+ * directory sizes. The cache-disabled path must rescan and sort on every
read, while the enabled
+ * path should reuse the immutable snapshot after warmup.
+ */
+ @Test
+ public void benchmarkRepeatedSortedWalFileReads() throws Exception {
Review Comment:
Adds an opt-in benchmark across multiple WAL file counts. It compares
repeated access with and without caching after warmup, so normal unit-test runs
remain deterministic and do not include timing assertions.
##########
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/wal/node/WALFileListCachePerformanceTest.java:
##########
@@ -0,0 +1,338 @@
+/*
+ * 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.iotdb.db.storageengine.dataregion.wal.node;
+
+import org.apache.iotdb.db.conf.IoTDBConfig;
+import org.apache.iotdb.db.conf.IoTDBDescriptor;
+import org.apache.iotdb.db.storageengine.dataregion.wal.utils.WALFileStatus;
+import org.apache.iotdb.db.storageengine.dataregion.wal.utils.WALFileUtils;
+import org.apache.iotdb.db.utils.EnvironmentUtils;
+import org.apache.iotdb.db.utils.constant.TestConstant;
+
+import com.sun.management.HotSpotDiagnosticMXBean;
+import org.apache.tsfile.utils.RamUsageEstimator;
+import org.junit.Assert;
+import org.junit.Assume;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.management.ManagementFactory;
+import java.util.Arrays;
+import java.util.Locale;
+import java.util.TreeMap;
+
+public class WALFileListCachePerformanceTest {
+
+ private static final String ENABLED_PROPERTY =
"iotdb.wal.file-list-cache.perf.enabled";
+ private static final String FILE_COUNTS_PROPERTY =
"iotdb.wal.file-list-cache.perf.file-counts";
+ private static final String WARMUP_READS_PROPERTY =
"iotdb.wal.file-list-cache.perf.warmup-reads";
+ private static final String READS_PROPERTY =
"iotdb.wal.file-list-cache.perf.reads";
+ private static final String ROUNDS_PROPERTY =
"iotdb.wal.file-list-cache.perf.rounds";
+
+ private static final String BASE_DIRECTORY =
+ TestConstant.BASE_OUTPUT_PATH.concat("wal-file-list-cache-performance");
+ private static final int[] DEFAULT_FILE_COUNTS = {1, 10, 100, 1000};
+
+ private static final IoTDBConfig CONFIG =
IoTDBDescriptor.getInstance().getConfig();
+
+ private static final long TREE_MAP_ENTRY_SHALLOW_SIZE =
getTreeMapEntryShallowSize();
+ private static final long FILE_SHALLOW_SIZE =
RamUsageEstimator.shallowSizeOfInstance(File.class);
+ private static final long LONG_SHALLOW_SIZE =
RamUsageEstimator.shallowSizeOfInstance(Long.class);
+ private static final long STRING_SHALLOW_SIZE =
+ RamUsageEstimator.shallowSizeOfInstance(String.class);
+ private static final boolean COMPACT_STRINGS_ENABLED =
isCompactStringsEnabled();
+
+ private static volatile long benchmarkBlackhole;
+
+ /**
+ * Compares repeated sorted-WAL-file reads with the cache disabled and
enabled for increasing
+ * directory sizes. The cache-disabled path must rescan and sort on every
read, while the enabled
+ * path should reuse the immutable snapshot after warmup.
+ */
+ @Test
+ public void benchmarkRepeatedSortedWalFileReads() throws Exception {
+ assumePerformanceTestEnabled();
+
+ final int[] fileCounts = parseFileCounts();
+ final int warmupReads = Integer.getInteger(WARMUP_READS_PROPERTY, 500);
+ final int reads = Integer.getInteger(READS_PROPERTY, 2000);
+ final int rounds = Integer.getInteger(ROUNDS_PROPERTY, 5);
+ Assert.assertTrue(warmupReads > 0);
+ Assert.assertTrue(reads > 0);
+ Assert.assertTrue(rounds > 0);
+
+ final boolean originalCacheEnabled = CONFIG.isWalFileListCacheEnabled();
+ EnvironmentUtils.cleanDir(BASE_DIRECTORY);
+ try {
+ for (int fileCount : fileCounts) {
+ runScenario(fileCount, warmupReads, reads, rounds);
+ }
+ } finally {
+ CONFIG.setWalFileListCacheEnabled(originalCacheEnabled);
+ EnvironmentUtils.cleanDir(BASE_DIRECTORY);
+ }
+ }
+
+ /**
+ * Estimates the retained heap added by enabling the cache for increasing
WAL directory sizes. The
+ * estimate uses the current JVM object layout and the actual cached file
paths, and separates the
+ * incrementally maintained index from the snapshot that is retained only
after first access.
+ */
+ @Test
+ public void measureRetainedWalFileListCacheMemory() throws Exception {
+ assumePerformanceTestEnabled();
+
Review Comment:
Adds an opt-in retained-memory estimate that separates the TreeMap index
from the lazily allocated snapshot. This makes the memory cost of enabling the
default observable for different directory sizes.
##########
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/wal/node/WalDeleteOutdatedNewTest.java:
##########
@@ -214,6 +218,10 @@ public void test03() throws IllegalPathException {
Assert.assertEquals(2, memTableIdsOfWal.get(0L).size());
File[] files = WALFileUtils.listAllWALFiles(new File(logDirectory1));
Assert.assertEquals(2, files.length);
+ Assert.assertNull(walNode1.getCachedSortedWalFiles());
+ walNode1.getDeletionBoundToFreeAtLeast(1);
+ File[] cachedWalFilesBeforeDeletion = walNode1.getCachedSortedWalFiles();
Review Comment:
Verifies that a deletion-bound access first publishes the cache and that
deleting an outdated WAL removes its version from the next snapshot, covering
incremental maintenance on the deletion path.
##########
iotdb-core/node-commons/src/assembly/resources/conf/iotdb-system.properties.template:
##########
@@ -1705,6 +1705,15 @@ wal_sync_mode_fsync_delay_in_ms=3
# Datatype: int
wal_buffer_size_in_byte=33554432
+# Whether to cache the sorted WAL file list in each WAL node.
+# Enabling this avoids scanning and sorting the WAL directory whenever the
file list is accessed,
+# including when a consensus request reader updates its files to search.
+# Keeping this enabled is especially recommended when IoTConsensus
synchronizes data through WAL
+# and synchronization latency is observed.
+# effectiveMode: restart
+# Datatype: boolean
+wal_file_list_cache_enabled=true
Review Comment:
Documents the enabled default and calls out the intended operational case:
IoTConsensus synchronization through WAL with observed synchronization latency.
The restart-only mode matches WALNode construction semantics.
--
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]