nsivabalan commented on code in PR #12097:
URL: https://github.com/apache/hudi/pull/12097#discussion_r1802144255
##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/action/BaseActionExecutor.java:
##########
@@ -62,6 +64,12 @@ public BaseActionExecutor(HoodieEngineContext context,
HoodieWriteConfig config,
* @param metadata commit metadata of interest.
*/
protected final void writeTableMetadata(HoodieCommitMetadata metadata,
HoodieData<WriteStatus> writeStatus, String actionType) {
+ // Recreate MDT for insert_overwrite_table operation.
+ if (WriteOperationType.INSERT_OVERWRITE_TABLE ==
metadata.getOperationType()) {
+ HoodieTableMetadataUtil.deleteMetadataTable(table.getMetaClient(),
table.getContext(), false);
Review Comment:
can you check if MDT is available and then trigger a delete?
##########
hudi-spark-datasource/hudi-spark/src/test/java/org/apache/hudi/TestMetadataTableSupport.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * 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;
+
+import org.apache.hudi.client.SparkRDDWriteClient;
+import org.apache.hudi.common.config.HoodieMetadataConfig;
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.common.table.timeline.HoodieActiveTimeline;
+import org.apache.hudi.common.table.timeline.HoodieInstant;
+import org.apache.hudi.config.HoodieCompactionConfig;
+import org.apache.hudi.config.HoodieWriteConfig;
+import org.apache.hudi.metadata.HoodieTableMetadata;
+import org.apache.hudi.storage.StoragePath;
+import org.apache.hudi.testutils.HoodieSparkClientTestBase;
+
+import org.apache.spark.api.java.JavaRDD;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.List;
+
+import static
org.apache.hudi.common.table.timeline.HoodieTimeline.REPLACE_COMMIT_ACTION;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class TestMetadataTableSupport extends HoodieSparkClientTestBase {
+ @BeforeEach
+ void start() throws Exception {
+ super.setUp();
+ }
+
+ @AfterEach
+ void end() throws Exception {
+ super.tearDown();
+ }
+
+ @Test
+ void testRecreateMDTForInsertOverwriteTableOperation() {
+ HoodieWriteConfig config = getConfigBuilder()
+ .withCompactionConfig(HoodieCompactionConfig.newBuilder()
+ .withMaxNumDeltaCommitsBeforeCompaction(1).build())
+ .withMetadataConfig(HoodieMetadataConfig.newBuilder()
+ .withEnableRecordIndex(true).build())
+ .build();
+
+ try (SparkRDDWriteClient writeClient = getHoodieWriteClient(config)) {
+ // Insert first batch.
+ String timestamp0 = "20241015000000000";
+ List<HoodieRecord> records0 = dataGen.generateInserts(timestamp0, 100);
+ JavaRDD<HoodieRecord> dataset0 = jsc.parallelize(records0, 2);
+
+ writeClient.startCommitWithTime(timestamp0);
+ writeClient.insert(dataset0, timestamp0).collect();
+
+ // Insert second batch.
+ String timestamp1 = "20241015000000001";
+ List<HoodieRecord> records1 = dataGen.generateInserts(timestamp1, 50);
+ JavaRDD<HoodieRecord> dataset1 = jsc.parallelize(records1, 2);
+
+ writeClient.startCommitWithTime(timestamp1, REPLACE_COMMIT_ACTION);
Review Comment:
before triggering "insert overwrite to data table", can you valida that MDT
is enabled.
and also, call our common validate method here
https://github.com/apache/hudi/blob/ece8d7c1b2740851daea9a1b9c98fa781d51e4f3/hudi-client/hudi-spark-client/src/test/java/org/apache/hudi/client/functional/TestHoodieBackedMetadata.java#L3525
##########
hudi-spark-datasource/hudi-spark/src/test/java/org/apache/hudi/TestMetadataTableSupport.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * 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;
+
+import org.apache.hudi.client.SparkRDDWriteClient;
+import org.apache.hudi.common.config.HoodieMetadataConfig;
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.common.table.timeline.HoodieActiveTimeline;
+import org.apache.hudi.common.table.timeline.HoodieInstant;
+import org.apache.hudi.config.HoodieCompactionConfig;
+import org.apache.hudi.config.HoodieWriteConfig;
+import org.apache.hudi.metadata.HoodieTableMetadata;
+import org.apache.hudi.storage.StoragePath;
+import org.apache.hudi.testutils.HoodieSparkClientTestBase;
+
+import org.apache.spark.api.java.JavaRDD;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.List;
+
+import static
org.apache.hudi.common.table.timeline.HoodieTimeline.REPLACE_COMMIT_ACTION;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class TestMetadataTableSupport extends HoodieSparkClientTestBase {
+ @BeforeEach
+ void start() throws Exception {
+ super.setUp();
+ }
+
+ @AfterEach
+ void end() throws Exception {
+ super.tearDown();
+ }
+
+ @Test
+ void testRecreateMDTForInsertOverwriteTableOperation() {
+ HoodieWriteConfig config = getConfigBuilder()
+ .withCompactionConfig(HoodieCompactionConfig.newBuilder()
+ .withMaxNumDeltaCommitsBeforeCompaction(1).build())
+ .withMetadataConfig(HoodieMetadataConfig.newBuilder()
+ .withEnableRecordIndex(true).build())
+ .build();
+
+ try (SparkRDDWriteClient writeClient = getHoodieWriteClient(config)) {
+ // Insert first batch.
+ String timestamp0 = "20241015000000000";
+ List<HoodieRecord> records0 = dataGen.generateInserts(timestamp0, 100);
+ JavaRDD<HoodieRecord> dataset0 = jsc.parallelize(records0, 2);
+
+ writeClient.startCommitWithTime(timestamp0);
+ writeClient.insert(dataset0, timestamp0).collect();
+
+ // Insert second batch.
+ String timestamp1 = "20241015000000001";
+ List<HoodieRecord> records1 = dataGen.generateInserts(timestamp1, 50);
+ JavaRDD<HoodieRecord> dataset1 = jsc.parallelize(records1, 2);
+
+ writeClient.startCommitWithTime(timestamp1, REPLACE_COMMIT_ACTION);
+ writeClient.insertOverwriteTable(dataset1, timestamp1);
+
+ // Validate.
+ StoragePath mdtBasePath =
+
HoodieTableMetadata.getMetadataTableBasePath(metaClient.getBasePath());
+ HoodieTableMetaClient mdtMetaClient = HoodieTableMetaClient.builder()
+ .setConf(storageConf.newInstance())
+ .setBasePath(mdtBasePath).build();
+
+ HoodieActiveTimeline timeline = mdtMetaClient.getActiveTimeline();
+ List<HoodieInstant> instants = timeline.getInstants();
+ assertEquals(3, timeline.getInstants().size());
+ // For MDT bootstrap instant.
+ assertEquals("00000000000000000", instants.get(0).getTimestamp());
+ // For RLI bootstrap instant.
+ assertEquals("00000000000000001", instants.get(1).getTimestamp());
+ // For the insert_overwrite_table instant.
+ assertEquals(timestamp1, instants.get(2).getTimestamp());
+ }
+ }
Review Comment:
in the end, we can validate that one of the commits in MDT (may be latest
completed) before triggering insert overwrite operation is not present anymore
in the end (after insert overwrite)
--
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]