Skip to content

Commit 6844c47

Browse files
authored
[Subscription] Fix stalled WAL replay retries across file refresh and rotation (#18919)
1 parent 9647e38 commit 6844c47

13 files changed

Lines changed: 471 additions & 49 deletions

File tree

‎iotdb-core/datanode/src/main/i18n/en/org/apache/iotdb/db/i18n/DataNodePipeMessages.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2270,6 +2270,12 @@ private DataNodePipeMessages() {}
22702270
MESSAGE_SUBSCRIPTION_WAL_REPLAY_SKIPPED_ARG_UNREADABLE_RETAINED_WAL_FILE_S_IN_QUEUE_ARG_REGION_ARG_HISTORICAL_DATA_MAY_BE_LOST_DETAILS_RECENT_FILES_FULL_DETAILS_IN_SERVER_LOG_ARG_FEDEFF7E =
22712271
"Subscription WAL replay skipped %d unreadable retained WAL file(s) in queue %s, region %s. Historical data may be lost. Details (recent files; full details in server log): %s";
22722272
public static final String MESSAGE_UNKNOWN_AD921D60 = "unknown";
2273+
public static final String
2274+
MESSAGE_WAL_METADATA_SNAPSHOT_FOR_FILE_ARG_VERSIONID_ARG_IS_UNAVAILABLE_AFTER_ROTATION_REPLAY_WILL_RETRY_WITHOUT_SKIPPING_D99C12A0 =
2275+
"WAL metadata snapshot for file %s (versionId=%d) is unavailable after rotation; replay will retry without skipping";
2276+
public static final String
2277+
EXCEPTION_WAL_FILE_ARG_VERSIONID_ARG_IS_MISSING_FROM_TWO_SUCCESSIVE_DIRECTORY_SCANS_AFTER_A_NEWER_WAL_FILE_BECAME_VISIBLE_1E170B4B =
2278+
"WAL file %s (versionId=%d) is missing from two successive directory scans after a newer WAL file became visible";
22732279
public static final String
22742280
MESSAGE_WAL_FILE_ARG_VERSIONID_ARG_ENTRYOFFSET_ARG_IS_TEMPORARILY_UNREADABLE_REPLAY_WILL_RETRY_WITHOUT_SKIPPING_ARG_EA11FBDD =
22752281
"WAL file %s (versionId=%d, entryOffset=%d) is temporarily unreadable; replay will retry without skipping: %s";

‎iotdb-core/datanode/src/main/i18n/zh/org/apache/iotdb/db/i18n/DataNodePipeMessages.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2111,6 +2111,12 @@ private DataNodePipeMessages() {}
21112111
MESSAGE_SUBSCRIPTION_WAL_REPLAY_SKIPPED_ARG_UNREADABLE_RETAINED_WAL_FILE_S_IN_QUEUE_ARG_REGION_ARG_HISTORICAL_DATA_MAY_BE_LOST_DETAILS_RECENT_FILES_FULL_DETAILS_IN_SERVER_LOG_ARG_FEDEFF7E =
21122112
"订阅 WAL 重放累计跳过了 %d 个无法读取的保留 WAL 文件,队列 %s,region %s。历史数据可能丢失。详情(近期文件;完整信息见服务端日志):%s";
21132113
public static final String MESSAGE_UNKNOWN_AD921D60 = "未知";
2114+
public static final String
2115+
MESSAGE_WAL_METADATA_SNAPSHOT_FOR_FILE_ARG_VERSIONID_ARG_IS_UNAVAILABLE_AFTER_ROTATION_REPLAY_WILL_RETRY_WITHOUT_SKIPPING_D99C12A0 =
2116+
"WAL 文件 %s(versionId=%d)在轮转后无法获取对应的元数据快照;回放将重试,不跳过该文件";
2117+
public static final String
2118+
EXCEPTION_WAL_FILE_ARG_VERSIONID_ARG_IS_MISSING_FROM_TWO_SUCCESSIVE_DIRECTORY_SCANS_AFTER_A_NEWER_WAL_FILE_BECAME_VISIBLE_1E170B4B =
2119+
"后继 WAL 文件可见后,WAL 文件 %s(versionId=%d)在连续两次目录扫描中均不存在";
21142120
public static final String
21152121
MESSAGE_WAL_FILE_ARG_VERSIONID_ARG_ENTRYOFFSET_ARG_IS_TEMPORARILY_UNREADABLE_REPLAY_WILL_RETRY_WITHOUT_SKIPPING_ARG_EA11FBDD =
21162122
"WAL 文件 %s(versionId=%d,entryOffset=%d)暂不可读;重放将重试而不跳过:%s";

‎iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/buffer/WALBuffer.java‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,17 @@ public WALMetaData getCurrentWALMetaDataSnapshot() {
893893
return writer == null ? new WALMetaData() : writer.snapshotMetaData();
894894
}
895895

896+
/** Returns null if rotation has already installed a writer for another file version. */
897+
public WALMetaData getWALMetaDataSnapshot(final long fileVersionId) {
898+
final WALWriter writer = currentWALFileWriter;
899+
// The writer and currentWALFileVersion are published separately during rotation. Bind the
900+
// snapshot to the captured writer itself, including while the version field is still old.
901+
return writer != null
902+
&& WALFileUtils.parseVersionId(writer.getLogFile().getName()) == fileVersionId
903+
? writer.snapshotMetaData()
904+
: null;
905+
}
906+
896907
public CheckpointManager getCheckpointManager() {
897908
return checkpointManager;
898909
}

‎iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/node/WALNode.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,6 +1090,10 @@ public WALMetaData getCurrentWALMetaDataSnapshot() {
10901090
return buffer.getCurrentWALMetaDataSnapshot();
10911091
}
10921092

1093+
public WALMetaData getWALMetaDataSnapshot(final long fileVersionId) {
1094+
return buffer.getWALMetaDataSnapshot(fileVersionId);
1095+
}
1096+
10931097
@Override
10941098
public long getTotalSize() {
10951099
return WALManager.getInstance().getTotalDiskUsage();

‎iotdb-core/datanode/src/main/java/org/apache/iotdb/db/subscription/broker/consensus/ConsensusPrefetchingQueue.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4741,8 +4741,8 @@ ProgressWALReader openProgressWALReader(final File walFile) throws IOException {
47414741
private static LiveWALMetaDataSnapshot captureLiveWALMetaDataSnapshot(final WALNode walNode) {
47424742
while (true) {
47434743
final long versionId = walNode.getCurrentWALFileVersion();
4744-
final WALMetaData metadata = walNode.getCurrentWALMetaDataSnapshot();
4745-
if (versionId == walNode.getCurrentWALFileVersion()) {
4744+
final WALMetaData metadata = walNode.getWALMetaDataSnapshot(versionId);
4745+
if (metadata != null && versionId == walNode.getCurrentWALFileVersion()) {
47464746
return new LiveWALMetaDataSnapshot(versionId, metadata);
47474747
}
47484748
}

0 commit comments

Comments
 (0)