-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix(load): validate TsFile before async move #18531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,7 +35,9 @@ | |
| import org.apache.iotdb.db.storageengine.load.active.ActiveLoadPathHelper; | ||
| import org.apache.iotdb.db.storageengine.load.disk.ILoadDiskSelector; | ||
|
|
||
| import org.apache.tsfile.common.conf.TSFileConfig; | ||
| import org.apache.tsfile.common.constant.TsFileConstant; | ||
| import org.apache.tsfile.read.TsFileSequenceReader; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
|
|
@@ -118,6 +120,11 @@ private static boolean loadTsFilesToActiveDir( | |
| return true; | ||
| } | ||
|
|
||
| // Validate before moving the source so ordinary or malformed files remain in place. | ||
| if (!isValidTsFile(file)) { | ||
| return false; | ||
| } | ||
|
|
||
| final File targetFilePath; | ||
| try { | ||
| targetFilePath = | ||
|
|
@@ -145,6 +152,19 @@ private static boolean loadTsFilesToActiveDir( | |
| return true; | ||
| } | ||
|
|
||
| private static boolean isValidTsFile(final File file) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P1] Apply this validation to the Pipe async path too
|
||
| if (!file.isFile() || !file.getName().endsWith(TsFileConstant.TSFILE_SUFFIX)) { | ||
| return false; | ||
| } | ||
| try (final TsFileSequenceReader reader = | ||
| new TsFileSequenceReader(file.getAbsolutePath(), false)) { | ||
| return TSFileConfig.MAGIC_STRING.equals(reader.readHeadMagic()) | ||
| && TSFileConfig.MAGIC_STRING.equals(reader.readTailMagic()); | ||
| } catch (Exception e) { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| private static Map<String, String> appendCurrentUserIfAbsent( | ||
| final Map<String, String> loadAttributes) { | ||
| final Map<String, String> attributes = | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P1] Validate the complete batch before moving any file
loadTsFileAsyncToActiveDircalls this method once per*.tsfile. If a directory contains a valid*.tsfilefollowed by a malformed*.tsfile, the valid file has already been copied/linked into the active-load directory before this call returnsfalsefor the malformed one.doAsyncLoadthen falls back to normal analysis, but the first file remains queued; withon-success='delete', its source may already be deleted as well. This can cause partial ingestion and unsafe retries. Validate all files before starting the transfer, or roll back every transfer when a later validation fails.