Copilot commented on code in PR #15276:
URL: https://github.com/apache/iotdb/pull/15276#discussion_r2030367657
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/connector/util/builder/PipeTreeModelTsFileBuilder.java:
##########
@@ -91,178 +105,201 @@ public synchronized void close() {
isTabletAlignedList.clear();
}
- private List<Pair<String, File>> writeTabletsToTsFiles()
- throws IOException, WriteProcessException {
- final Map<String, List<Tablet>> device2Tablets = new HashMap<>();
- final Map<String, Boolean> device2Aligned = new HashMap<>();
+ private List<Pair<String, File>> writeTabletsToTsFiles() throws
WriteProcessException {
+ final List<Pair<String, File>> sealedFiles = new ArrayList<>();
+ try (final RestorableTsFileIOWriter writer = new
RestorableTsFileIOWriter(createFile())) {
+ writeTabletsIntoOneFile(writer);
+ sealedFiles.add(new Pair<>(null, writer.getFile()));
+ } catch (final Exception e) {
+ LOGGER.warn(
+ "Batch id = {}: Failed to write tablets into tsfile, because {}",
+ currentBatchId.get(),
+ e.getMessage(),
+ e);
+ // TODO: handle ex
+ throw new WriteProcessException(e);
Review Comment:
The exception handling block still contains a 'TODO: handle ex' comment and
rethrows the exception without comprehensive resource cleanup; consider
implementing a robust exception handling strategy.
```suggestion
if (writer != null) {
try {
writer.close();
} catch (IOException ioException) {
LOGGER.error("Failed to close writer after exception",
ioException);
}
}
throw new WriteProcessException(e);
} finally {
if (writer != null && !writer.isClosed()) {
try {
writer.close();
} catch (IOException e) {
LOGGER.error("Failed to close writer in finally block", e);
}
}
```
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/connector/util/builder/PipeTreeModelTsFileBuilder.java:
##########
@@ -91,178 +105,201 @@ public synchronized void close() {
isTabletAlignedList.clear();
}
- private List<Pair<String, File>> writeTabletsToTsFiles()
- throws IOException, WriteProcessException {
- final Map<String, List<Tablet>> device2Tablets = new HashMap<>();
- final Map<String, Boolean> device2Aligned = new HashMap<>();
+ private List<Pair<String, File>> writeTabletsToTsFiles() throws
WriteProcessException {
+ final List<Pair<String, File>> sealedFiles = new ArrayList<>();
+ try (final RestorableTsFileIOWriter writer = new
RestorableTsFileIOWriter(createFile())) {
+ writeTabletsIntoOneFile(writer);
+ sealedFiles.add(new Pair<>(null, writer.getFile()));
+ } catch (final Exception e) {
+ LOGGER.warn(
+ "Batch id = {}: Failed to write tablets into tsfile, because {}",
+ currentBatchId.get(),
+ e.getMessage(),
+ e);
+ // TODO: handle ex
+ throw new WriteProcessException(e);
+ }
+
+ return sealedFiles;
+ }
+
+ private void writeTabletsIntoOneFile(final RestorableTsFileIOWriter writer)
throws Exception {
+ // TODO: database & region
+ final String database = "test_db";
+ final String dataRegionId = "test_dr";
Review Comment:
Hardcoded placeholder values (e.g., 'test_db', 'test_dr', and 'test_id') are
present; consider refactoring to utilize configuration settings or parameters
to ensure production readiness.
```suggestion
final String database = System.getenv().getOrDefault("DATABASE_NAME",
"default_db");
final String dataRegionId =
System.getenv().getOrDefault("DATA_REGION_ID", "default_dr");
```
--
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]