Skip to content

Commit

Permalink
[FLINK-35893][cdc-runtime] Write CURRENT_VERSION of TableChangeInfo t…
Browse files Browse the repository at this point in the history
…o state

This closes #2944.
  • Loading branch information
leonardBang committed Aug 7, 2024
1 parent 4561a8a commit 03a2ae3
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,14 @@ public static TableChangeInfo of(
/** Serializer for {@link TableChangeInfo}. */
public static class Serializer implements SimpleVersionedSerializer<TableChangeInfo> {

/** The latest version before change of state compatibility. */
public static final int VERSION_BEFORE_STATE_COMPATIBILITY = 1;

public static final int CURRENT_VERSION = 2;

/** Used to distinguish with the state which CURRENT_VERSION was not written. */
public static final TableId MAGIC_TABLE_ID = TableId.tableId("__magic_table__");

@Override
public int getVersion() {
return CURRENT_VERSION;
Expand All @@ -122,6 +128,8 @@ public byte[] serialize(TableChangeInfo tableChangeInfo) throws IOException {
SchemaSerializer schemaSerializer = SchemaSerializer.INSTANCE;
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(baos)) {
tableIdSerializer.serialize(MAGIC_TABLE_ID, new DataOutputViewStreamWrapper(out));
out.writeInt(CURRENT_VERSION);
tableIdSerializer.serialize(
tableChangeInfo.getTableId(), new DataOutputViewStreamWrapper(out));
schemaSerializer.serialize(
Expand All @@ -139,6 +147,12 @@ public TableChangeInfo deserialize(int version, byte[] serialized) throws IOExce
try (ByteArrayInputStream bais = new ByteArrayInputStream(serialized);
DataInputStream in = new DataInputStream(bais)) {
TableId tableId = tableIdSerializer.deserialize(new DataInputViewStreamWrapper(in));
if (tableId.equals(MAGIC_TABLE_ID)) {
version = in.readInt();
tableId = tableIdSerializer.deserialize(new DataInputViewStreamWrapper(in));
} else {
version = VERSION_BEFORE_STATE_COMPATIBILITY;
}
Schema originalSchema =
schemaSerializer.deserialize(version, new DataInputViewStreamWrapper(in));
Schema transformedSchema =
Expand Down

0 comments on commit 03a2ae3

Please sign in to comment.