Skip to content

Fix schema file I/O failure handling and short writes - #19190

Open
Caideyipi wants to merge 1 commit into
masterfrom
fix/schema-file-io-failure-handling
Open

Caideyipi wants to merge 1 commit into
masterfrom
fix/schema-file-io-failure-handling

Conversation

@Caideyipi

Copy link
Copy Markdown
Collaborator

Description

Schema-file initialization, shutdown, and positional writes can leave incomplete data or open resources after an I/O failure. This change writes the initial header immediately, completes short header and page writes, and attempts all cleanup steps while preserving the original exception.

  • Write headers and pages until their buffers are exhausted, advancing the file offset by the actual number of bytes written. Fail immediately if a write makes no progress.
  • Keep a page dirty after a failed write. A subsequent flush starts at the beginning of the page and writes the entire page again.
  • Persist a valid initial header after creating or clearing a schema file. If initialization of a new file fails, close resources and truncate the partial file so initialization can be retried.
  • Close schema-file read, write, and log resources on shutdown and initialization/recovery failures. Report the first failure and retain later cleanup failures as suppressed exceptions.
  • Add regression tests and English/Chinese messages for writes that make no progress.

Failure examples

Trigger Previous behavior Behavior with this change
A 16 KiB page is written in chunks of 4,093 bytes The first short write could be accepted as a complete flush and the page marked clean. Writes continue for 4,093 + 4,093 + 4,093 + 4,093 + 12 bytes, advancing both the buffer position and file offset. The page becomes clean only after all 16,384 bytes are written.
A page write consumes 3 bytes, then the next write returns 0 or throws an IOException A single short write could return successfully without attempting the remainder. Zero progress fails immediately; an IOException is propagated unchanged. The page stays dirty, and a retry starts from the page's original file offset with the full page.
SchemaFile.clear() recreates the file and it is reopened before a later header update The new file could contain its root page without a valid persisted header. Initialization persists the complete header, allowing the recreated file to be reopened.
A header write or page-manager close fails during SchemaFile.close() The exception could prevent subsequent resources from being closed. Remaining cleanup steps are attempted, the first exception is rethrown, and later failures are attached as suppressed exceptions.

Validation

  • Spotless and git diff --check passed.
  • A local isolated build started from a clean source reactor: SchemaPageTest and SchemaFileTest passed, with 26 tests, 0 failures, 0 errors, and 0 skipped. All newly added tests were run locally.
  • The initial isolated build stopped at formatting because patch application introduced CRLF line endings. After normalization to LF, the build and tests passed.
  • Chinese-locale clean test-compile passed for the 28 relevant reactor modules. This does not establish that the full repository compiles with the Chinese locale.
  • Remote tests were not run because Maven Central was unreachable. Cluster integration tests were not run.
  • These are the completed pre-publication checks; publication preserves the reviewed source contents without rerunning the checks.

This PR has:

  • been self-reviewed.
  • added unit tests to cover the changed code paths.
Key changed classes

SchemaFile, SchemaPage, PageIOChannel, PageManager

@sonarqubecloud

sonarqubecloud Bot commented Nov 9, 2026

Copy link
Copy Markdown

@codecov

codecov Bot commented Nov 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 67.16418% with 44 lines in your changes missing coverage. Please review.
✅ Project coverage is 48.80%. Comparing base (36c35f6) to head (7a36a4f).

Files with missing lines Patch % Lines
...egion/mtree/impl/pbtree/schemafile/SchemaFile.java 68.05% 23 Missing ⚠️
.../impl/pbtree/schemafile/pagemgr/PageIOChannel.java 53.65% 19 Missing ⚠️
...ee/impl/pbtree/schemafile/pagemgr/PageManager.java 85.71% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #19190      +/-   ##
============================================
- Coverage     48.80%   48.80%   -0.01%     
  Complexity      674      674              
============================================
  Files          5574     5574              
  Lines        412836   412926      +90     
  Branches      54448    54459      +11     
============================================
+ Hits         201480   201517      +37     
- Misses       211356   211409      +53     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant