Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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.heap;
import org.apache.flink.annotation.VisibleForTesting;
import org.apache.flink.api.common.ExecutionConfig;
import org.apache.flink.api.common.typeutils.TypeSerializer;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.core.fs.FSDataInputStream;
import org.apache.flink.core.memory.DataInputView;
import org.apache.flink.core.memory.DataInputViewStreamWrapper;
import org.apache.flink.core.memory.DataOutputViewStreamWrapper;
import org.apache.flink.runtime.checkpoint.CheckpointOptions;
import org.apache.flink.runtime.io.async.AbstractAsyncCallableWithResources;
import org.apache.flink.runtime.io.async.AsyncStoppableTaskWithCallback;
import org.apache.flink.runtime.query.TaskKvStateRegistry;
import org.apache.flink.runtime.state.CheckpointStreamFactory;
import org.apache.flink.runtime.state.CheckpointStreamWithResultProvider;
import org.apache.flink.runtime.state.CheckpointedStateScope;
import org.apache.flink.runtime.state.InternalBackendSerializationProxy;
import org.apache.flink.runtime.state.KeyGroupsStateSnapshot;
import org.apache.flink.runtime.state.DoneFuture;
import org.apache.flink.runtime.state.KeyGroupRange;
import org.apache.flink.runtime.state.KeyedStateHandle;
import org.apache.flink.runtime.state.LocalRecoveryConfig;
import org.apache.flink.runtime.state.RegisteredStateMetaInfo;
import org.apache.flink.runtime.state.SnappyStreamCompressionDecorator;
import org.apache.flink.runtime.state.SnapshotResult;
import org.apache.flink.runtime.state.StateMetaInfoSnapshot;
import org.apache.flink.runtime.state.StreamCompressionDecorator;
import org.apache.flink.runtime.state.StreamStateHandle;
import org.apache.flink.runtime.state.UncompressedStreamCompressionDecorator;
import org.apache.flink.runtime.state.VoidNamespace;
import org.apache.flink.runtime.state.AbstractInternalStateBackend;
import org.apache.flink.runtime.state.StateStorage;
import org.apache.flink.runtime.state.heap.internal.StateTable;
import org.apache.flink.runtime.state.heap.internal.StateTableSnapshot;
import org.apache.flink.runtime.state.keyed.KeyedState;
import org.apache.flink.runtime.state.keyed.KeyedStateDescriptor;
import org.apache.flink.runtime.state.subkeyed.SubKeyedState;
import org.apache.flink.runtime.state.subkeyed.SubKeyedStateDescriptor;
import org.apache.flink.util.IOUtils;
import org.apache.flink.util.Preconditions;
import org.apache.flink.util.function.SupplierWithException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Nonnull;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.RunnableFuture;
import java.util.stream.Collectors;
/**
* Implementation of {@link AbstractInternalStateBackend} which stores the key-value
* pairs of states on the Java Heap.
*/
public class HeapInternalStateBackend extends AbstractInternalStateBackend {
private static final Logger LOG = LoggerFactory.getLogger(HeapInternalStateBackend.class);
/**
* The configuration for local recovery.
*/
private final LocalRecoveryConfig localRecoveryConfig;
/**
* Whether this backend supports async snapshot.
*/
private final boolean asynchronousSnapshot;
public HeapInternalStateBackend(
int numberOfGroups,
KeyGroupRange keyGroupRange,
ClassLoader userClassLoader,
LocalRecoveryConfig localRecoveryConfig,
TaskKvStateRegistry kvStateRegistry,
boolean asynchronousSnapshot,
ExecutionConfig executionConfig
) {
super(numberOfGroups, keyGroupRange, userClassLoader, kvStateRegistry, executionConfig);
this.localRecoveryConfig = Preconditions.checkNotNull(localRecoveryConfig);
this.asynchronousSnapshot = asynchronousSnapshot;
LOG.info("HeapInternalStateBackend is created with {} mode.", (asynchronousSnapshot ? "async" : "sync"));
}
@Override
public void closeImpl() {
}
@Override
@SuppressWarnings("unchecked")
protected StateStorage getOrCreateStateStorageForKeyedState(RegisteredStateMetaInfo stateMetaInfo) {
HeapStateStorage stateStorage = (HeapStateStorage) stateStorages.get(stateMetaInfo.getName());
if (stateStorage == null) {
stateStorage = new HeapStateStorage<>(
this,
stateMetaInfo,
VoidNamespace.INSTANCE,
false,
asynchronousSnapshot
);
stateStorages.put(stateMetaInfo.getName(), stateStorage);
}
stateStorage.setStateMetaInfo(stateMetaInfo);
return stateStorage;
}
@Override
@SuppressWarnings("unchecked")
protected StateStorage getOrCreateStateStorageForSubKeyedState(RegisteredStateMetaInfo stateMetaInfo) {
HeapStateStorage stateStorage = (HeapStateStorage) stateStorages.get(stateMetaInfo.getName());
if (stateStorage == null) {
stateStorage = new HeapStateStorage<>(
this,
stateMetaInfo,
null,
true,
asynchronousSnapshot
);
stateStorages.put(stateMetaInfo.getName(), stateStorage);
}
stateStorage.setStateMetaInfo(stateMetaInfo);
return stateStorage;
}
@Override
public int numStateEntries() {
int count = 0;
List