Search in sources :

Example 11 with HoodieRollbackException

use of org.apache.hudi.exception.HoodieRollbackException in project hudi by apache.

the class TestHoodieClientOnCopyOnWriteStorage method testRollbackAfterConsistencyCheckFailureUsingFileList.

private void testRollbackAfterConsistencyCheckFailureUsingFileList(boolean rollbackUsingMarkers, boolean enableOptimisticConsistencyGuard, boolean populateMetaFields) throws Exception {
    String instantTime = "00000000000010";
    HoodieTableMetaClient metaClient = HoodieTableMetaClient.builder().setConf(hadoopConf).setBasePath(basePath).build();
    Properties properties = new Properties();
    if (!populateMetaFields) {
        properties = getPropertiesForKeyGen();
    }
    HoodieWriteConfig cfg = !enableOptimisticConsistencyGuard ? getConfigBuilder().withRollbackUsingMarkers(rollbackUsingMarkers).withAutoCommit(false).withConsistencyGuardConfig(ConsistencyGuardConfig.newBuilder().withConsistencyCheckEnabled(true).withMaxConsistencyCheckIntervalMs(1).withInitialConsistencyCheckIntervalMs(1).withEnableOptimisticConsistencyGuard(enableOptimisticConsistencyGuard).build()).build() : getConfigBuilder().withRollbackUsingMarkers(rollbackUsingMarkers).withAutoCommit(false).withConsistencyGuardConfig(ConsistencyGuardConfig.newBuilder().withConsistencyCheckEnabled(true).withEnableOptimisticConsistencyGuard(enableOptimisticConsistencyGuard).withOptimisticConsistencyGuardSleepTimeMs(1).build()).withProperties(properties).build();
    SparkRDDWriteClient client = getHoodieWriteClient(cfg);
    testConsistencyCheck(metaClient, instantTime, enableOptimisticConsistencyGuard);
    if (!enableOptimisticConsistencyGuard) {
        // Rollback of this commit should succeed with FailSafeCG
        client.rollback(instantTime);
        assertFalse(testTable.commitExists(instantTime), "After explicit rollback, commit file should not be present");
        // Marker directory must be removed after rollback
        assertFalse(metaClient.getFs().exists(new Path(metaClient.getMarkerFolderPath(instantTime))));
    } else {
        // if optimistic CG is enabled, commit should have succeeded.
        assertTrue(testTable.commitExists(instantTime), "With optimistic CG, first commit should succeed. commit file should be present");
        // Marker directory must be removed after rollback
        assertFalse(metaClient.getFs().exists(new Path(metaClient.getMarkerFolderPath(instantTime))));
        if (rollbackUsingMarkers) {
            // rollback of a completed commit should fail if marked based rollback is used.
            try {
                client.rollback(instantTime);
                fail("Rollback of completed commit should throw exception");
            } catch (HoodieRollbackException e) {
            // ignore
            }
        } else {
            // rollback of a completed commit should succeed if using list based rollback
            client.rollback(instantTime);
            assertFalse(testTable.commitExists(instantTime), "After explicit rollback, commit file should not be present");
        }
    }
}
Also used : HoodieTableMetaClient(org.apache.hudi.common.table.HoodieTableMetaClient) Path(org.apache.hadoop.fs.Path) SparkRDDWriteClient(org.apache.hudi.client.SparkRDDWriteClient) HoodieRollbackException(org.apache.hudi.exception.HoodieRollbackException) HoodieWriteConfig(org.apache.hudi.config.HoodieWriteConfig) Properties(java.util.Properties) TypedProperties(org.apache.hudi.common.config.TypedProperties)

Aggregations

HoodieRollbackException (org.apache.hudi.exception.HoodieRollbackException)11 IOException (java.io.IOException)7 HoodieInstant (org.apache.hudi.common.table.timeline.HoodieInstant)5 HoodieWriteConfig (org.apache.hudi.config.HoodieWriteConfig)5 Collections (java.util.Collections)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 HoodieEngineContext (org.apache.hudi.common.engine.HoodieEngineContext)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Path (org.apache.hadoop.fs.Path)3 HoodieRollbackMetadata (org.apache.hudi.avro.model.HoodieRollbackMetadata)3 HoodieRollbackRequest (org.apache.hudi.avro.model.HoodieRollbackRequest)3 TransactionManager (org.apache.hudi.client.transaction.TransactionManager)3 HoodieRollbackStat (org.apache.hudi.common.HoodieRollbackStat)3 HoodieTimeline (org.apache.hudi.common.table.timeline.HoodieTimeline)3 HoodieIOException (org.apache.hudi.exception.HoodieIOException)3 LogManager (org.apache.log4j.LogManager)3 Logger (org.apache.log4j.Logger)3 ArrayList (java.util.ArrayList)2