All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.flink.runtime.state.SharedStateRegistry Maven / Gradle / Ivy

/*
 * 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.runtime.state;

import org.apache.flink.runtime.checkpoint.CompletedCheckpoint;
import org.apache.flink.runtime.jobgraph.RestoreMode;

/**
 * This registry manages state that is shared across (incremental) checkpoints, and is responsible
 * for deleting shared state that is no longer used in any valid checkpoint.
 *
 * 

A {@code SharedStateRegistry} will be deployed in the {@link * org.apache.flink.runtime.checkpoint.CheckpointCoordinator CheckpointCoordinator} to keep track of * usage of {@link StreamStateHandle}s by a key that (logically) identifies them. */ public interface SharedStateRegistry extends AutoCloseable { /** A singleton object for the default implementation of a {@link SharedStateRegistryFactory} */ SharedStateRegistryFactory DEFAULT_FACTORY = (deleteExecutor, checkpoints, restoreMode) -> { SharedStateRegistry sharedStateRegistry = new SharedStateRegistryImpl(deleteExecutor); for (CompletedCheckpoint checkpoint : checkpoints) { checkpoint.registerSharedStatesAfterRestored(sharedStateRegistry, restoreMode); } return sharedStateRegistry; }; /** * Register a reference to the given shared state in the registry. If there is already a state * handle registered under the given key, the "new" state handle is disposed . * *

IMPORTANT: caller should check the state handle returned by the result, because the * registry is performing de-duplication and could potentially return a handle that is supposed * to replace the one from the registration request. * * @param state the shared state for which we register a reference. * @param checkpointID which uses the state * @return the result of this registration request, consisting of the state handle that is * registered under the key by the end of the operation and its current reference count. */ StreamStateHandle registerReference( SharedStateRegistryKey registrationKey, StreamStateHandle state, long checkpointID); /** * Unregister state that is not referenced by the given checkpoint ID or any newer. * * @param lowestCheckpointID which is still valid */ void unregisterUnusedState(long lowestCheckpointID); /** * Register given shared states in the registry. * *

NOTE: For state from checkpoints from other jobs or runs (i.e. after recovery), please use * {@link #registerAllAfterRestored(CompletedCheckpoint, RestoreMode)} * * @param stateHandles The shared states to register. * @param checkpointID which uses the states. */ void registerAll(Iterable stateHandles, long checkpointID); /** * Set the lowest checkpoint ID below which no state is discarded, inclusive. * *

After recovery from an incremental checkpoint, its state should NOT be discarded, even if * {@link #unregisterUnusedState(long) not used} anymore (unless recovering in {@link * RestoreMode#CLAIM CLAIM} mode). * *

This should hold for both cases: when recovering from that initial checkpoint; and from * any subsequent checkpoint derived from it. */ void registerAllAfterRestored(CompletedCheckpoint checkpoint, RestoreMode mode); void checkpointCompleted(long checkpointId); }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy