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 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 io.streamnative.pulsar.handlers.kop.storage;
import com.google.common.annotations.VisibleForTesting;
import io.streamnative.pulsar.handlers.kop.DelayedFetch;
import io.streamnative.pulsar.handlers.kop.KafkaServiceConfiguration;
import io.streamnative.pulsar.handlers.kop.KafkaTopicLookupService;
import io.streamnative.pulsar.handlers.kop.MessageFetchContext;
import io.streamnative.pulsar.handlers.kop.RequestStats;
import io.streamnative.pulsar.handlers.kop.exceptions.KoPTopicInitializeException;
import io.streamnative.pulsar.handlers.kop.utils.KopTopic;
import io.streamnative.pulsar.handlers.kop.utils.delayed.DelayedOperation;
import io.streamnative.pulsar.handlers.kop.utils.delayed.DelayedOperationKey;
import io.streamnative.pulsar.handlers.kop.utils.delayed.DelayedOperationPurgatory;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.apache.bookkeeper.common.util.OrderedExecutor;
import org.apache.commons.lang3.mutable.MutableBoolean;
import org.apache.commons.lang3.mutable.MutableLong;
import org.apache.kafka.common.IsolationLevel;
import org.apache.kafka.common.TopicPartition;
import org.apache.kafka.common.errors.InvalidProducerEpochException;
import org.apache.kafka.common.errors.InvalidTopicException;
import org.apache.kafka.common.errors.NotLeaderOrFollowerException;
import org.apache.kafka.common.message.FetchRequestData;
import org.apache.kafka.common.protocol.Errors;
import org.apache.kafka.common.record.MemoryRecords;
import org.apache.kafka.common.requests.ProduceResponse;
import org.apache.kafka.common.utils.SystemTime;
import org.apache.kafka.common.utils.Time;
import org.apache.pulsar.broker.service.BrokerServiceException;
import org.apache.pulsar.broker.service.plugin.EntryFilter;
import org.apache.pulsar.client.api.PulsarClientException;
import org.apache.pulsar.common.util.FutureUtil;
/**
* Used to append records. Mapping to Kafka ReplicaManager.scala.
*/
@Slf4j
public class ReplicaManager {
private final PartitionLogManager logManager;
private final DelayedOperationPurgatory fetchPurgatory;
private final String metadataNamespace;
public ReplicaManager(KafkaServiceConfiguration kafkaConfig,
RequestStats requestStats,
Time time,
List entryFilters,
DelayedOperationPurgatory fetchPurgatory,
KafkaTopicLookupService kafkaTopicLookupService,
Function producerStateManagerSnapshotBuffer,
OrderedExecutor recoveryExecutor) {
this.logManager = new PartitionLogManager(kafkaConfig, requestStats, entryFilters,
time, kafkaTopicLookupService, producerStateManagerSnapshotBuffer, recoveryExecutor);
this.fetchPurgatory = fetchPurgatory;
this.metadataNamespace = kafkaConfig.getKafkaMetadataNamespace();
}
public PartitionLog getPartitionLog(TopicPartition topicPartition,
String namespacePrefix) {
return logManager.getLog(topicPartition, namespacePrefix);
}
public void removePartitionLog(String topicName) {
PartitionLog partitionLog = logManager.removeLog(topicName);
if (log.isDebugEnabled() && partitionLog != null) {
log.debug("PartitionLog: {} has bean removed.", topicName);
}
}
@VisibleForTesting
public int size() {
return logManager.size();
}
public CompletableFuture