flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tillrohrmann <...@git.apache.org>
Subject [GitHub] flink pull request #5737: [FLINK-8721][flip6] Handle archiving failures for ...
Date Thu, 22 Mar 2018 18:03:35 GMT
Github user tillrohrmann commented on a diff in the pull request:

    https://github.com/apache/flink/pull/5737#discussion_r176516910
  
    --- Diff: flink-core/src/main/java/org/apache/flink/util/OptionalFailure.java ---
    @@ -0,0 +1,112 @@
    +/*
    + * 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.flink.util;
    +
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import javax.annotation.Nullable;
    +
    +import java.io.Serializable;
    +import java.util.Objects;
    +import java.util.function.Supplier;
    +
    +import static org.apache.flink.util.Preconditions.checkNotNull;
    +
    +/**
    + * Wrapper around an object representing either a success (with a given value) or a failure
cause.
    + */
    +public class OptionalFailure<T> implements Serializable {
    +	private static final long serialVersionUID = 1L;
    +
    +	private static final Logger LOG = LoggerFactory.getLogger(OptionalFailure.class);
    +
    +	@Nullable
    +	private T value;
    +
    +	@Nullable
    +	private Throwable failureCause;
    +
    +	private OptionalFailure(@Nullable T value, @Nullable Throwable failureCause) {
    +		this.value = value;
    +		this.failureCause = failureCause;
    +	}
    +
    +	public static <T> OptionalFailure<T> of(T value) {
    +		return new OptionalFailure<>(value, null);
    +	}
    +
    +	public static <T> OptionalFailure<T> ofFailure(Throwable failureCause) {
    +		return new OptionalFailure<>(null, failureCause);
    +	}
    +
    +	/**
    +	 * @return wrapped {@link OptionalFailure} returned by {@code valueSupplier} or wrapped
failure if
    +	 * {@code valueSupplier} has thrown a {@link RuntimeException}.
    +	 */
    +	public static <T> OptionalFailure<T> createFrom(Supplier<T> valueSupplier)
{
    +		try {
    +			return OptionalFailure.of(valueSupplier.get());
    +		}
    +		catch (RuntimeException ex) {
    +			LOG.error("Failed to archive accumulators", ex);
    --- End diff --
    
    The message indicates that `OptionalFailure` was implemented for the accumulators in mind,
but I think it should be more generic. I guess that `AccumulatorHelper#67` is also the reason
why we catch the `RuntimeException` to make the merge supplier as smooth as possible.


---

Mime
View raw message