yujun777 commented on code in PR #68193:
URL: https://github.com/apache/doris/pull/68193#discussion_r4057122484
##########
fe/fe-core/src/test/java/org/apache/doris/mtmv/AlterMTMVTest.java:
##########
@@ -403,6 +405,44 @@ public void testAlterIvmInfoPersistence() throws Exception
{
Assertions.assertEquals(schemaChangeVersion,
mtmv.getSchemaChangeVersion());
}
+ @Test
+ public void testReplayAlterPartitionStates() throws Exception {
+ Config.enable_table_stream = true;
+ createDatabaseAndUse("alter_partition_states_test");
+ createTable("CREATE TABLE alter_partition_states_test.states_base (k1
int, v1 int)\n"
+ + "DUPLICATE KEY(k1)\n"
+ + "DISTRIBUTED BY HASH(k1) BUCKETS 1\n"
+ + "PROPERTIES ('replication_num' = '1', 'binlog.enable' =
'true', 'binlog.format' = 'ROW')");
+ createMvByNereids("CREATE MATERIALIZED VIEW states_mv\n"
+ + " BUILD DEFERRED REFRESH INCREMENTAL ON MANUAL\n"
+ + " DISTRIBUTED BY RANDOM BUCKETS 2\n"
+ + " PROPERTIES ('replication_num' = '1')\n"
+ + " AS SELECT k1, v1 FROM states_base");
+
+ MTMV mtmv = (MTMV) Env.getCurrentInternalCatalog()
+ .getDb("alter_partition_states_test").get()
+ .getTableOrMetaException("states_mv");
+ String partitionName = mtmv.getPartitionNames().iterator().next();
+
+ MTMVPartitionState state = new MTMVPartitionState(0, 1);
+ Map<String, MTMVPartitionState> states = new LinkedHashMap<>();
+ states.put(partitionName, state);
+ TableNameInfo tableName = new TableNameInfo(mtmv.getQualifiedDbName(),
mtmv.getName());
+ AlterMTMV replayAlter = new AlterMTMV(tableName,
MTMVAlterOpType.ALTER_PARTITION_STATES);
+ replayAlter.setPartitionStates(states);
+ // The live map keeps moving after the payload was taken; the payload
must not follow it.
+ state.setLatestEpoch(7);
+ // The MV starts without any state, so only the replayed payload can
put it there.
+ mtmv.alterPartitionStates(Map.of());
+
+ Env.getCurrentEnv().getAlterInstance().processAlterMTMV(replayAlter,
true);
Review Comment:
Addressed in 14e53728905.
`AlterMTMVTest.testReplayAlterPartitionStates` now drives the bytes the edit
log writes: the record goes through `AlterMTMV.write` into a `DataOutputStream`
and back through `AlterMTMV.read`, and only what comes out of that is replayed,
so a dropped or mis-serialized op or `pst` member can no longer leave the test
green. It covers the three shapes: a payload with state (applied), a payload
with an empty map (states emptied, with the serialized member name asserted on
the journal bytes), and a payload without the member (states left alone). The
ADD_TASK payload gets the same treatment in `MTMVTest`, where the captured
payload is round-tripped through JSON before the state is read back.
The absent case found a real collapse. The ALTER_PARTITION_STATES branch
applied a null payload as an empty map, so replaying a record without the
member emptied the states instead of preserving them, while the task-result
replay had always checked for null. `alterPartitionStates` now ignores a null
payload, so both paths agree.
Both shapes are covered because they arise differently: an ADD_TASK record
can genuinely predate the member -- that is the older-journal case, built in
the test by removing `pst` from the serialized record -- whereas an
ALTER_PARTITION_STATES record always ships with it, so its absent case guards
against a future writer that forgets to set it rather than against an old
journal.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]