You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by "jw-itq (via GitHub)" <gi...@apache.org> on 2025/09/12 07:50:52 UTC
[PR] Compatible with serialization of old version checkpoints [seatunnel]
jw-itq opened a new pull request, #9854:
URL: https://github.com/apache/seatunnel/pull/9854
<!--
Thank you for contributing to SeaTunnel! Please make sure that your code changes
are covered with tests. And in case of new features or big changes
remember to adjust the documentation.
Feel free to ping committers for the review!
## Contribution Checklist
- Make sure that the pull request corresponds to a [GITHUB issue](https://github.com/apache/seatunnel/issues).
- Name the pull request in the form "[Feature] [component] Title of the pull request", where *Feature* can be replaced by `Hotfix`, `Bug`, etc.
- Minor fixes should be named following this pattern: `[hotfix] [docs] Fix typo in README.md doc`.
-->
### Purpose of this pull request
<!-- Describe the purpose of this pull request. For example: This pull request adds checkstyle plugin.-->
https://github.com/apache/seatunnel/issues/9845
### Does this PR introduce _any_ user-facing change?
<!--
Note that it means *any* user-facing change including all aspects such as the documentation fix.
If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
If possible, please also clarify if this is a user-facing change compared to the released SeaTunnel versions or within the unreleased branches such as dev.
If no, write 'No'.
If you are adding/modifying connector documents, please follow our new specifications: https://github.com/apache/seatunnel/issues/4544.
-->
### How was this patch tested?
<!--
If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
If tests were not added, please describe why they were not added and/or why it was difficult to add.
If you are adding E2E test cases, maybe refer to https://github.com/apache/seatunnel/blob/dev/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-cdc-mysql-e2e/src/test/resources/mysqlcdc_to_mysql.conf, here is a good example.
-->
### Check list
* [x] If any new Jar binary package adding in your PR, please add License Notice according
[New License Guide](https://github.com/apache/seatunnel/blob/dev/docs/en/contribution/new-license.md)
* [x] If necessary, please update the documentation to describe the new feature. https://github.com/apache/seatunnel/tree/dev/docs
* [x] If you are contributing the connector code, please check that the following files are updated:
1. Update [plugin-mapping.properties](https://github.com/apache/seatunnel/blob/dev/plugin-mapping.properties) and add new connector information in it
2. Update the pom file of [seatunnel-dist](https://github.com/apache/seatunnel/blob/dev/seatunnel-dist/pom.xml)
3. Add ci label in [label-scope-conf](https://github.com/apache/seatunnel/blob/dev/.github/workflows/labeler/label-scope-conf.yml)
4. Add e2e testcase in [seatunnel-e2e](https://github.com/apache/seatunnel/tree/dev/seatunnel-e2e/seatunnel-connector-v2-e2e/)
5. Update connector [plugin_config](https://github.com/apache/seatunnel/blob/dev/config/plugin_config)
--
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: commits-unsubscribe@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Fix] Compatible with serialization of old version checkpoints [seatunnel]
Posted by "jw-itq (via GitHub)" <gi...@apache.org>.
jw-itq commented on PR #9854:
URL: https://github.com/apache/seatunnel/pull/9854#issuecomment-3290174896
> Could you share the core logic? I found all new method is private scope.
@Hisoka-X thanks. I'm not sure if this issue needs to be resolved, but I think it would be helpful for someone like me who needs to upgrade to ensure correct backward compatibility during checkpoint restore.
I think we can also close this PR, is there a unified way to handle it in the future.
### Core Logic for Backward Compatibility in SeaTunnel TableSchema Deserialization
### Background
In SeaTunnel version 2.3.12, the [TableSchema](file:///Users/shiwanming/job/package-swm/seatunnel/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/TableSchema.java#L46-L231) class was refactored: the [columns](file:///Users/shiwanming/job/package-swm/seatunnel/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/AbstractSchema.java#L34-L34) field was moved from the [TableSchema](file:///Users/shiwanming/job/package-swm/seatunnel/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/TableSchema.java#L46-L231) class into its parent class [AbstractSchema](file:///Users/shiwanming/job/package-swm/seatunnel/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/AbstractSchema.java#L31-L85). This change introduced a backward compatibility issue — data serialized with pre-2.3.12 versions cannot be correctly deserialized in the new version.
### Core Logic Steps
#### Step 1: Custom Deserialization Method
Implement a private [readObject](file:///Users/shiwanming/job/package-swm/seatunnel/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/TableSchema.java#L108-L108) method to customize the deserialization process — a standard extension point provided by Java’s serialization mechanism:
```java
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException
```
#### Step 2: Read Serialized Fields
Use `ObjectInputStream.GetField` to read all fields from the serialized data. This approach supports reading data serialized by any version:
```java
ObjectInputStream.GetField fields = stream.readFields();
```
#### Step 3: Version Detection
Attempt to read the [columns](file:///Users/shiwanming/job/package-swm/seatunnel/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/AbstractSchema.java#L34-L34) field — which existed only in the old version — to determine the data version:
```java
List<Column> columns = null;
try {
columns = (List<Column>) fields.get("columns", null);
} catch (IllegalArgumentException e) {
columns = null; // Field does not exist in newer versions
}
```
- If [columns](file:///Users/shiwanming/job/package-swm/seatunnel/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/AbstractSchema.java#L34-L34) is not null → data is from an old version.
- If [columns](file:///Users/shiwanming/job/package-swm/seatunnel/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/AbstractSchema.java#L34-L34) is null → data is from a new version.
#### Step 4: Compatibility Handling
If old-version data is detected, invoke the [initializeParentFields](file:///Users/shiwanming/job/package-swm/seatunnel/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/TableSchema.java#L124-L139) method to populate the [columns](file:///Users/shiwanming/job/package-swm/seatunnel/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/AbstractSchema.java#L34-L34) data into the parent class [AbstractSchema](file:///Users/shiwanming/job/package-swm/seatunnel/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/AbstractSchema.java#L31-L85):
```java
if (columns != null) {
initializeParentFields(columns);
}
```
#### Step 5: Initialize Parent Class Fields
Use reflection to assign the legacy [columns](file:///Users/shiwanming/job/package-swm/seatunnel/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/AbstractSchema.java#L34-L34) data into the corresponding fields of the parent class [AbstractSchema](file:///Users/shiwanming/job/package-swm/seatunnel/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/AbstractSchema.java#L31-L85):
```java
private void initializeParentFields(List<Column> columns) {
// Set the 'columns' field in the parent class
java.lang.reflect.Field columnsField = AbstractSchema.class.getDeclaredField("columns");
columnsField.setAccessible(true);
setFinalField(columnsField, this, columns);
// Set the 'columnNames' field in the parent class
List<String> columnNames = columns.stream().map(Column::getName).collect(Collectors.toList());
java.lang.reflect.Field columnNamesField = AbstractSchema.class.getDeclaredField("columnNames");
columnNamesField.setAccessible(true);
setFinalField(columnNamesField, this, columnNames);
}
```
#### Step 6: Handle Final Fields
Since the [columns](file:///Users/shiwanming/job/package-swm/seatunnel/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/AbstractSchema.java#L34-L34) and [columnNames](file:///Users/shiwanming/job/package-swm/seatunnel/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/AbstractSchema.java#L37-L37) fields in [AbstractSchema](file:///Users/shiwanming/job/package-swm/seatunnel/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/AbstractSchema.java#L31-L85) are declared as `final`, special handling is required:
```java
private void setFinalField(java.lang.reflect.Field field, Object target, Object value)
```
This method supports multiple JDK versions:
1. **JDK 8–11**: Remove the `FINAL` modifier via reflection.
2. **JDK 17+**: Use the `Unsafe` API.
3. **Fallback**: Direct field access (if other methods fail).
--
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: commits-unsubscribe@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Fix] Compatible with serialization of old version checkpoints [seatunnel]
Posted by "Hisoka-X (via GitHub)" <gi...@apache.org>.
Hisoka-X closed pull request #9854: [Fix] Compatible with serialization of old version checkpoints
URL: https://github.com/apache/seatunnel/pull/9854
--
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: commits-unsubscribe@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Fix] Compatible with serialization of old version checkpoints [seatunnel]
Posted by "Hisoka-X (via GitHub)" <gi...@apache.org>.
Hisoka-X commented on code in PR #9854:
URL: https://github.com/apache/seatunnel/pull/9854#discussion_r2349115726
##########
seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/TableSchema.java:
##########
@@ -92,4 +94,113 @@ public TableSchema copy() {
.primaryKey(primaryKey == null ? null : primaryKey.copy())
.build();
}
+
+ /**
+ * Custom deserialization to handle compatibility with older versions.
+ *
+ * <p>In older versions (before 2.3.12), TableSchema directly contained columns field. In newer
+ * versions, TableSchema extends AbstractSchema which contains columns field.
+ *
+ * <p>This method ensures that old checkpoint data can be properly deserialized by using
+ * ObjectInputStream.GetField to read old version fields and properly initialize the parent
+ * class fields.
+ */
+ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
Review Comment:
This is good code, but I'm not sure we need to merge it into our mainline. Cross-version checkpoint compatibility scenarios are minimal.
--
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: commits-unsubscribe@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org