Search in sources :

Example 11 with FlinkRuntimeException

use of org.apache.flink.util.FlinkRuntimeException in project flink by apache.

the class HiveTableSink method consume.

private DataStreamSink<?> consume(ProviderContext providerContext, DataStream<RowData> dataStream, boolean isBounded, DataStructureConverter converter) {
    checkAcidTable(catalogTable.getOptions(), identifier.toObjectPath());
    try (HiveMetastoreClientWrapper client = HiveMetastoreClientFactory.create(HiveConfUtils.create(jobConf), hiveVersion)) {
        Table table = client.getTable(identifier.getDatabaseName(), identifier.getObjectName());
        StorageDescriptor sd = table.getSd();
        Class hiveOutputFormatClz = hiveShim.getHiveOutputFormatClass(Class.forName(sd.getOutputFormat()));
        boolean isCompressed = jobConf.getBoolean(HiveConf.ConfVars.COMPRESSRESULT.varname, false);
        HiveWriterFactory writerFactory = new HiveWriterFactory(jobConf, hiveOutputFormatClz, sd.getSerdeInfo(), tableSchema, getPartitionKeyArray(), HiveReflectionUtils.getTableMetadata(hiveShim, table), hiveShim, isCompressed);
        String extension = Utilities.getFileExtension(jobConf, isCompressed, (HiveOutputFormat<?, ?>) hiveOutputFormatClz.newInstance());
        OutputFileConfig.OutputFileConfigBuilder fileNamingBuilder = OutputFileConfig.builder().withPartPrefix("part-" + UUID.randomUUID().toString()).withPartSuffix(extension == null ? "" : extension);
        final int parallelism = Optional.ofNullable(configuredParallelism).orElse(dataStream.getParallelism());
        if (isBounded) {
            OutputFileConfig fileNaming = fileNamingBuilder.build();
            return createBatchSink(dataStream, converter, sd, writerFactory, fileNaming, parallelism);
        } else {
            if (overwrite) {
                throw new IllegalStateException("Streaming mode not support overwrite.");
            }
            Properties tableProps = HiveReflectionUtils.getTableMetadata(hiveShim, table);
            return createStreamSink(providerContext, dataStream, sd, tableProps, writerFactory, fileNamingBuilder, parallelism);
        }
    } catch (TException e) {
        throw new CatalogException("Failed to query Hive metaStore", e);
    } catch (IOException e) {
        throw new FlinkRuntimeException("Failed to create staging dir", e);
    } catch (ClassNotFoundException e) {
        throw new FlinkHiveException("Failed to get output format class", e);
    } catch (IllegalAccessException | InstantiationException e) {
        throw new FlinkHiveException("Failed to instantiate output format instance", e);
    }
}
Also used : TException(org.apache.thrift.TException) CatalogTable(org.apache.flink.table.catalog.CatalogTable) Table(org.apache.hadoop.hive.metastore.api.Table) HiveTableUtil.checkAcidTable(org.apache.flink.table.catalog.hive.util.HiveTableUtil.checkAcidTable) StorageDescriptor(org.apache.hadoop.hive.metastore.api.StorageDescriptor) CatalogException(org.apache.flink.table.catalog.exceptions.CatalogException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) Properties(java.util.Properties) OutputFileConfig(org.apache.flink.streaming.api.functions.sink.filesystem.OutputFileConfig) HiveMetastoreClientWrapper(org.apache.flink.table.catalog.hive.client.HiveMetastoreClientWrapper) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) HiveWriterFactory(org.apache.flink.connectors.hive.write.HiveWriterFactory)

Example 12 with FlinkRuntimeException

use of org.apache.flink.util.FlinkRuntimeException in project flink by apache.

the class PulsarCommitter method commit.

@Override
public void commit(Collection<CommitRequest<PulsarCommittable>> requests) throws IOException, InterruptedException {
    TransactionCoordinatorClient client = transactionCoordinatorClient();
    for (CommitRequest<PulsarCommittable> request : requests) {
        PulsarCommittable committable = request.getCommittable();
        TxnID txnID = committable.getTxnID();
        String topic = committable.getTopic();
        LOG.debug("Start committing the Pulsar transaction {} for topic {}", txnID, topic);
        try {
            client.commit(txnID);
        } catch (TransactionCoordinatorClientException e) {
            // This is a known bug for Pulsar Transaction.
            // We have to use instanceof instead of catching them.
            TransactionCoordinatorClientException ex = PulsarTransactionUtils.unwrap(e);
            if (ex instanceof CoordinatorNotFoundException) {
                LOG.error("We couldn't find the Transaction Coordinator from Pulsar broker {}. " + "Check your broker configuration.", committable, ex);
                request.signalFailedWithKnownReason(ex);
            } else if (ex instanceof InvalidTxnStatusException) {
                LOG.error("Unable to commit transaction ({}) because it's in an invalid state. " + "Most likely the transaction has been aborted for some reason. " + "Please check the Pulsar broker logs for more details.", committable, ex);
                request.signalAlreadyCommitted();
            } else if (ex instanceof TransactionNotFoundException) {
                if (request.getNumberOfRetries() == 0) {
                    LOG.error("Unable to commit transaction ({}) because it's not found on Pulsar broker. " + "Most likely the checkpoint interval exceed the transaction timeout.", committable, ex);
                    request.signalFailedWithKnownReason(ex);
                } else {
                    LOG.warn("We can't find the transaction {} after {} retry committing. " + "This may mean that the transaction have been committed in previous but failed with timeout. " + "So we just mark it as committed.", txnID, request.getNumberOfRetries());
                    request.signalAlreadyCommitted();
                }
            } else if (ex instanceof MetaStoreHandlerNotExistsException) {
                LOG.error("We can't find the meta store handler by the mostSigBits from TxnID {}. " + "Did you change the metadata for topic {}?", committable, TRANSACTION_COORDINATOR_ASSIGN, ex);
                request.signalFailedWithKnownReason(ex);
            } else {
                LOG.error("Encountered retriable exception while committing transaction {} for topic {}.", committable, topic, ex);
                int maxRecommitTimes = sinkConfiguration.getMaxRecommitTimes();
                if (request.getNumberOfRetries() < maxRecommitTimes) {
                    request.retryLater();
                } else {
                    String message = String.format("Failed to commit transaction %s after retrying %d times", txnID, maxRecommitTimes);
                    request.signalFailedWithKnownReason(new FlinkRuntimeException(message, ex));
                }
            }
        } catch (Exception e) {
            LOG.error("Transaction ({}) encountered unknown error and data could be potentially lost.", committable, e);
            request.signalFailedWithUnknownReason(e);
        }
    }
}
Also used : InvalidTxnStatusException(org.apache.pulsar.client.api.transaction.TransactionCoordinatorClientException.InvalidTxnStatusException) TransactionNotFoundException(org.apache.pulsar.client.api.transaction.TransactionCoordinatorClientException.TransactionNotFoundException) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) MetaStoreHandlerNotExistsException(org.apache.pulsar.client.api.transaction.TransactionCoordinatorClientException.MetaStoreHandlerNotExistsException) TransactionCoordinatorClientException(org.apache.pulsar.client.api.transaction.TransactionCoordinatorClientException) IOException(java.io.IOException) InvalidTxnStatusException(org.apache.pulsar.client.api.transaction.TransactionCoordinatorClientException.InvalidTxnStatusException) CoordinatorNotFoundException(org.apache.pulsar.client.api.transaction.TransactionCoordinatorClientException.CoordinatorNotFoundException) TransactionNotFoundException(org.apache.pulsar.client.api.transaction.TransactionCoordinatorClientException.TransactionNotFoundException) TxnID(org.apache.pulsar.client.api.transaction.TxnID) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) MetaStoreHandlerNotExistsException(org.apache.pulsar.client.api.transaction.TransactionCoordinatorClientException.MetaStoreHandlerNotExistsException) TransactionCoordinatorClientException(org.apache.pulsar.client.api.transaction.TransactionCoordinatorClientException) TransactionCoordinatorClient(org.apache.pulsar.client.api.transaction.TransactionCoordinatorClient) CoordinatorNotFoundException(org.apache.pulsar.client.api.transaction.TransactionCoordinatorClientException.CoordinatorNotFoundException)

Example 13 with FlinkRuntimeException

use of org.apache.flink.util.FlinkRuntimeException in project flink by apache.

the class TopicProducerRegister method abortTransactions.

/**
 * Abort the existed transactions. This method would be used when closing PulsarWriter.
 */
private void abortTransactions() {
    if (transactionRegister.isEmpty()) {
        return;
    }
    TransactionCoordinatorClient coordinatorClient = ((PulsarClientImpl) pulsarClient).getTcClient();
    // This null check is used for making sure transaction is enabled in client.
    checkNotNull(coordinatorClient);
    try (Closer closer = Closer.create()) {
        for (Transaction transaction : transactionRegister.values()) {
            TxnID txnID = transaction.getTxnID();
            closer.register(() -> coordinatorClient.abort(txnID));
        }
        clearTransactions();
    } catch (IOException e) {
        throw new FlinkRuntimeException(e);
    }
}
Also used : Closer(org.apache.flink.shaded.guava30.com.google.common.io.Closer) TxnID(org.apache.pulsar.client.api.transaction.TxnID) PulsarTransactionUtils.createTransaction(org.apache.flink.connector.pulsar.common.utils.PulsarTransactionUtils.createTransaction) Transaction(org.apache.pulsar.client.api.transaction.Transaction) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) PulsarClientImpl(org.apache.pulsar.client.impl.PulsarClientImpl) IOException(java.io.IOException) TransactionCoordinatorClient(org.apache.pulsar.client.api.transaction.TransactionCoordinatorClient)

Example 14 with FlinkRuntimeException

use of org.apache.flink.util.FlinkRuntimeException in project flink by apache.

the class TtlAggregateFunction method getResult.

@Override
public OUT getResult(TtlValue<ACC> accumulator) {
    Preconditions.checkNotNull(updater, "State updater should be set in TtlAggregatingState");
    Preconditions.checkNotNull(stateClear, "State clearing should be set in TtlAggregatingState");
    ACC userAcc;
    try {
        userAcc = getWithTtlCheckAndUpdate(() -> accumulator, updater, stateClear);
    } catch (Exception e) {
        throw new FlinkRuntimeException("Failed to retrieve original internal aggregating state", e);
    }
    return userAcc == null ? null : original.getResult(userAcc);
}
Also used : FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException)

Example 15 with FlinkRuntimeException

use of org.apache.flink.util.FlinkRuntimeException in project flink by apache.

the class ApplicationDispatcherBootstrapTest method testErrorHandlerIsCalledWhenSubmissionThrowsAnException.

@Test
public void testErrorHandlerIsCalledWhenSubmissionThrowsAnException() throws Exception {
    final AtomicBoolean shutdownCalled = new AtomicBoolean(false);
    final TestingDispatcherGateway.Builder dispatcherBuilder = runningJobGatewayBuilder().setSubmitFunction(jobGraph -> {
        throw new FlinkRuntimeException("Nope!");
    }).setClusterShutdownFunction(status -> {
        shutdownCalled.set(true);
        return CompletableFuture.completedFuture(Acknowledge.get());
    });
    // we're "listening" on this to be completed to verify that the error handler is called.
    // In production, this will shut down the cluster with an exception.
    final CompletableFuture<Void> errorHandlerFuture = new CompletableFuture<>();
    final ApplicationDispatcherBootstrap bootstrap = createApplicationDispatcherBootstrap(2, dispatcherBuilder.build(), scheduledExecutor, errorHandlerFuture::completeExceptionally);
    final CompletableFuture<Acknowledge> completionFuture = bootstrap.getBootstrapCompletionFuture();
    // we call the error handler
    assertException(errorHandlerFuture, FlinkRuntimeException.class);
    // we return a future that is completed exceptionally
    assertException(completionFuture, FlinkRuntimeException.class);
    // and cluster shutdown didn't get called
    assertFalse(shutdownCalled.get());
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) ProgramInvocationException(org.apache.flink.client.program.ProgramInvocationException) ScheduledFuture(java.util.concurrent.ScheduledFuture) ExceptionUtils(org.apache.flink.util.ExceptionUtils) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Duration(java.time.Duration) Assertions(org.assertj.core.api.Assertions) FailingJob(org.apache.flink.client.testjar.FailingJob) ScheduledExecutor(org.apache.flink.util.concurrent.ScheduledExecutor) Acknowledge(org.apache.flink.runtime.messages.Acknowledge) Executors(java.util.concurrent.Executors) ExecutorUtils(org.apache.flink.util.ExecutorUtils) Test(org.junit.jupiter.api.Test) FlinkJobNotFoundException(org.apache.flink.runtime.messages.FlinkJobNotFoundException) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) SerializedThrowable(org.apache.flink.util.SerializedThrowable) Optional(java.util.Optional) PackagedProgram(org.apache.flink.client.program.PackagedProgram) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) FlinkException(org.apache.flink.util.FlinkException) ScheduledExecutorServiceAdapter(org.apache.flink.util.concurrent.ScheduledExecutorServiceAdapter) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) EnumSource(org.junit.jupiter.params.provider.EnumSource) CompletableFuture(java.util.concurrent.CompletableFuture) JobStatus(org.apache.flink.api.common.JobStatus) DispatcherGateway(org.apache.flink.runtime.dispatcher.DispatcherGateway) Supplier(java.util.function.Supplier) EmbeddedExecutor(org.apache.flink.client.deployment.application.executors.EmbeddedExecutor) PipelineOptionsInternal(org.apache.flink.configuration.PipelineOptionsInternal) MultiExecuteJob(org.apache.flink.client.testjar.MultiExecuteJob) JobResult(org.apache.flink.runtime.jobmaster.JobResult) TestLoggerExtension(org.apache.flink.util.TestLoggerExtension) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) FatalErrorHandler(org.apache.flink.runtime.rpc.FatalErrorHandler) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) BiConsumer(java.util.function.BiConsumer) DeploymentOptions(org.apache.flink.configuration.DeploymentOptions) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) JobExecutionException(org.apache.flink.runtime.client.JobExecutionException) HighAvailabilityMode(org.apache.flink.runtime.jobmanager.HighAvailabilityMode) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) ApplicationStatus(org.apache.flink.runtime.clusterframework.ApplicationStatus) Configuration(org.apache.flink.configuration.Configuration) JobCancellationException(org.apache.flink.runtime.client.JobCancellationException) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) AfterEach(org.junit.jupiter.api.AfterEach) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) JobID(org.apache.flink.api.common.JobID) TestingDispatcherGateway(org.apache.flink.runtime.webmonitor.TestingDispatcherGateway) Collections(java.util.Collections) HighAvailabilityOptions(org.apache.flink.configuration.HighAvailabilityOptions) DuplicateJobSubmissionException(org.apache.flink.runtime.client.DuplicateJobSubmissionException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestingDispatcherGateway(org.apache.flink.runtime.webmonitor.TestingDispatcherGateway) CompletableFuture(java.util.concurrent.CompletableFuture) Acknowledge(org.apache.flink.runtime.messages.Acknowledge) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

FlinkRuntimeException (org.apache.flink.util.FlinkRuntimeException)78 IOException (java.io.IOException)28 Test (org.junit.Test)13 JobID (org.apache.flink.api.common.JobID)10 HashMap (java.util.HashMap)8 ArrayList (java.util.ArrayList)7 CompletableFuture (java.util.concurrent.CompletableFuture)7 ExecutionException (java.util.concurrent.ExecutionException)7 Nonnull (javax.annotation.Nonnull)7 Configuration (org.apache.flink.configuration.Configuration)6 Collectors (java.util.stream.Collectors)5 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)5 JobResultStore (org.apache.flink.runtime.highavailability.JobResultStore)4 RocksDBException (org.rocksdb.RocksDBException)4 List (java.util.List)3 Map (java.util.Map)3 CheckpointMetrics (org.apache.flink.runtime.checkpoint.CheckpointMetrics)3 TaskStateSnapshot (org.apache.flink.runtime.checkpoint.TaskStateSnapshot)3 ExecutionAttemptID (org.apache.flink.runtime.executiongraph.ExecutionAttemptID)3 JobResult (org.apache.flink.runtime.jobmaster.JobResult)3