Repository navigation
Fence IoTConsensus applies before storage shutdown - #18841
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #18841 +/- ##
============================================
+ Coverage 45.91% 45.98% +0.07%
Complexity 712 712
============================================
Files 5502 5502
Lines 398778 399176 +398
Branches 51968 52047 +79
============================================
+ Hits 183094 183575 +481
+ Misses 215684 215601 -83 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
jt2594838
reviewed
Oct 14, 2026
jt2594838
approved these changes
Oct 15, 2026
This was referenced Oct 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
An IoTConsensus SyncLog request can pass the read-only check, remain queued or pause before apply, and then write after StorageEngine and WALManager have stopped. In the supplied
testPipeAfterDataRegionLeaderStoplogs, the sender replica used byp2has already lostt200: its TsFile starts at201, while the other replica's starts at200, and the compaction totals differ by the row's eight fields.The late successful write recreates a WAL node in its existing directory. The new CheckpointManager appends another header to
_0.checkpointwhere recovery expects records, leaving the late memtable absent from checkpoint recovery. Actual WAL/TsFile recovery then produces an empty TsFile even when the late WAL was fully drained and normally closed. A late write before WAL shutdown does not recreate the node and remains recoverable, explaining why a flush-only reproducer did not demonstrate the loss.Fence complete IoTConsensus applies against shutdown with a per-DataRegion lifecycle lock. Each apply attempt holds the shared side through the data mutation and WAL separator, checks read-only/stopping/closed admission under that lock, and releases it before any retry delay. Shutdown takes the exclusive side to drain admitted applies and permanently close admission before the final WAL drain and TsFile close. StorageEngine stop and forced shutdown also close admission. This covers both local writes and remote applies; a request that passed an earlier check is either included in the final flush or rejected without reopening WAL/TsFile processors.
The lifecycle lock is separate from the insertion lock so memory backpressure can still be relieved by ordinary flushing and snapshot closing does not introduce an inverse lock order. The consensus-layer check remains an early rejection for queued batches. Existing retry handling rejects the remaining batch and does not advance the applied frontier. The generic DataRegionStateMachine apply path retains its existing behavior for other consensus protocols.
The cluster tests check every replica's outgoing replication lag before flushing or restarting. The table-model test also checks sender data after restart, before creating
p2, to distinguish source-side loss from pipe transfer failure.Regression coverage
200) instead of read-only (600).Validation
mvn -nsu test-compile -P with-zh-locale -DskipTestspassed.mvn -nsu package -pl integration-test -am -P with-integration-tests -DskipTestspassed (39 modules).IoTDBPipeClusterIT#testPipeAfterDataRegionLeaderStoppassed in 138.5 seconds withMultiClusterIT2DualTableManualEnhancedandHighPerformanceMode(two data replicas). Logs confirm the post-restart sender check,p2creation/history extraction, and normal completion through the final receiver assertions.git diff --checkpassed.Normal-write performance
Compared with the pre-fix baseline (
9b29f1cf009), the fixed version (d878e7be265) was measured on192.168.130.19with JDK 17.0.9 using JMH. The benchmark kept the node in the normalRunningstate and used ASYNC WAL; ReadOnly and shutdown paths were excluded.The lifecycle admission path adds about 14.6 ns per apply in a single-thread microbenchmark. Under artificial contention on one DataRegion, the added cost was about 638 ns/op with four threads and 1.96 us/op with eight threads. In the real DataRegion state-machine write benchmark, single-thread throughput changed by +1.7% for single-row writes and -1.4% for batches of 100 rows, both within normal benchmark variance. Four threads directly competing on one DataRegion showed roughly 2%-4% variation, while distributing eight threads across eight DataRegions showed no consistent regression. The direct same-DataRegion contention test is an upper-bound stress case because normal
IoTConsensusServerImpl.write()already serializes state-machine access.The expected normal-write cost is therefore a tens-of-nanoseconds admission check, generally below 1% for single-row writes and lower for larger batches.