danny0405 commented on code in PR #19940: URL: https://github.com/apache/hudi/pull/19940#discussion_r4012021024
########## hudi-utilities/src/test/java/org/apache/hudi/utilities/streamer/TestErrorTableWriteOnce.java: ########## @@ -0,0 +1,167 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.hudi.utilities.streamer; + +import org.apache.hudi.client.WriteStatus; +import org.apache.hudi.common.config.HoodieMetadataConfig; +import org.apache.hudi.common.model.HoodieAvroPayload; +import org.apache.hudi.common.model.HoodieRecord; +import org.apache.hudi.common.model.HoodieTableType; +import org.apache.hudi.common.table.HoodieTableMetaClient; +import org.apache.hudi.common.testutils.HoodieTestDataGenerator; +import org.apache.hudi.common.util.Option; +import org.apache.hudi.config.HoodieWriteConfig; +import org.apache.hudi.testutils.SparkClientFunctionalTestHarness; + +import org.apache.spark.api.java.JavaRDD; +import org.apache.spark.storage.StorageLevel; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * Covers the error-table write landing exactly once under + * {@code hoodie.errortable.write.unification.enabled=true}, over a real error table so the commit + * really does release the write statuses it was given. + */ +class TestErrorTableWriteOnce extends SparkClientFunctionalTestHarness { + + private static final int ERROR_RECORD_COUNT = 20; + private static final String BASE_TABLE_INSTANT = "20260913120000000"; + + /** Counting before the commit, the order {@code StreamSync} uses. */ + @Test + void countingBeforeCommitWritesEachErrorRecordOnce() throws Exception { + Fixture fixture = newFixture(); + try (RddBackedErrorTableWriter writer = fixture.writer) { + JavaRDD<WriteStatus> writeStatusRDD = writer.upsert(BASE_TABLE_INSTANT, Option.empty()); + assertNotEquals(StorageLevel.NONE(), writeStatusRDD.getStorageLevel(), + "the write persists its statuses; counting before the commit relies on that cache"); + + SuccessfulRecordCounter.Counts counts = SuccessfulRecordCounter.compute( + new ArrayList<>(), Option.of(writeStatusRDD), true); + assertTrue(ErrorTableCommitter.commit(writer, Option.of(writeStatusRDD), true, + BASE_TABLE_INSTANT, Option.empty()), "error table commit should succeed"); Review Comment: [P2] Exercise the production ordering in the regression test This test calls `SuccessfulRecordCounter.compute` and `ErrorTableCommitter.commit` directly in the desired order, but never invokes `StreamSync`. Both helpers are unchanged from the base branch, so reverting the entire production change in `StreamSync` would leave both new tests passing, including the test that explicitly expects duplicates. Could we add a test that runs a streamer batch with this RDD-backed writer and write unification enabled, then asserts each error-table key appears once? That assertion should fail when only the `StreamSync` reorder is reverted, so the suite catches a recurrence of the actual bug. -- 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]
