Search in sources :

Example 1 with UnknownLocationException

use of org.apache.flink.queryablestate.exceptions.UnknownLocationException in project flink by apache.

the class KvStateClientProxyHandler method getKvStateLookupInfo.

/**
 * Lookup the {@link KvStateLocation} for the given job and queryable state name.
 *
 * <p>The job manager will be queried for the location only if forced or no cached location can
 * be found. There are no guarantees about
 *
 * @param jobId JobID the state instance belongs to.
 * @param queryableStateName Name under which the state instance has been published.
 * @param forceUpdate Flag to indicate whether to force a update via the lookup service.
 * @return Future holding the KvStateLocation
 */
private CompletableFuture<KvStateLocation> getKvStateLookupInfo(final JobID jobId, final String queryableStateName, final boolean forceUpdate) {
    final Tuple2<JobID, String> cacheKey = new Tuple2<>(jobId, queryableStateName);
    final CompletableFuture<KvStateLocation> cachedFuture = lookupCache.get(cacheKey);
    if (!forceUpdate && cachedFuture != null && !cachedFuture.isCompletedExceptionally()) {
        LOG.debug("Retrieving location for state={} of job={} from the cache.", queryableStateName, jobId);
        return cachedFuture;
    }
    final KvStateLocationOracle kvStateLocationOracle = proxy.getKvStateLocationOracle(jobId);
    if (kvStateLocationOracle != null) {
        LOG.debug("Retrieving location for state={} of job={} from the key-value state location oracle.", queryableStateName, jobId);
        final CompletableFuture<KvStateLocation> location = new CompletableFuture<>();
        lookupCache.put(cacheKey, location);
        kvStateLocationOracle.requestKvStateLocation(jobId, queryableStateName).whenComplete((KvStateLocation kvStateLocation, Throwable throwable) -> {
            if (throwable != null) {
                if (ExceptionUtils.stripCompletionException(throwable) instanceof FlinkJobNotFoundException) {
                    // if the jobId was wrong, remove the entry from the cache.
                    lookupCache.remove(cacheKey);
                }
                location.completeExceptionally(throwable);
            } else {
                location.complete(kvStateLocation);
            }
        });
        return location;
    } else {
        return FutureUtils.completedExceptionally(new UnknownLocationException("Could not retrieve location of state=" + queryableStateName + " of job=" + jobId + ". Potential reasons are: i) the state is not ready, or ii) the job does not exist."));
    }
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) Tuple2(org.apache.flink.api.java.tuple.Tuple2) FlinkJobNotFoundException(org.apache.flink.runtime.messages.FlinkJobNotFoundException) UnknownLocationException(org.apache.flink.queryablestate.exceptions.UnknownLocationException) KvStateLocationOracle(org.apache.flink.runtime.jobmaster.KvStateLocationOracle) JobID(org.apache.flink.api.common.JobID) KvStateLocation(org.apache.flink.runtime.query.KvStateLocation)

Aggregations

CompletableFuture (java.util.concurrent.CompletableFuture)1 JobID (org.apache.flink.api.common.JobID)1 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)1 UnknownLocationException (org.apache.flink.queryablestate.exceptions.UnknownLocationException)1 KvStateLocationOracle (org.apache.flink.runtime.jobmaster.KvStateLocationOracle)1 FlinkJobNotFoundException (org.apache.flink.runtime.messages.FlinkJobNotFoundException)1 KvStateLocation (org.apache.flink.runtime.query.KvStateLocation)1