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.
/**
* Copyright (c) 2019 - 2024 StreamNative, Inc.. All Rights Reserved.
*/
/**
* 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.KsnTopicPartition;
import io.streamnative.pulsar.handlers.kop.MessageFetchContext;
import io.streamnative.pulsar.handlers.kop.RequestStats;
import io.streamnative.pulsar.handlers.kop.ShadowNamespaceLoadManager;
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.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.bookkeeper.common.util.MathUtils;
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.InvalidTopicException;
import org.apache.kafka.common.message.DescribeProducersResponseData;
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.naming.TopicName;
import org.apache.pulsar.common.util.FutureUtil;
/**
* Used to append records. Mapping to Kafka ReplicaManager.scala.
*/
@Slf4j
public class ReplicaManager {
@Getter
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,
ProducerStateManagerSnapshotBufferFactory producerStateManagerSnapshotBufferFactory,
OrderedExecutor recoveryExecutor) {
this.logManager = new PartitionLogManager(kafkaConfig, requestStats, entryFilters,
time, kafkaTopicLookupService, producerStateManagerSnapshotBufferFactory, recoveryExecutor);
this.fetchPurgatory = fetchPurgatory;
this.metadataNamespace = kafkaConfig.getKafkaMetadataNamespace();
}
public PartitionLog getPartitionLog(String fullPartitionName) {
// TODO: Make `getPartitionLog` async to avoid blocking the current thread
return logManager.getLog(fullPartitionName);
}
public void removePartitionLog(String topicName) {
PartitionLog partitionLog = logManager.removeAndCloseLog(topicName);
if (log.isDebugEnabled() && partitionLog != null) {
log.debug("PartitionLog: {} has bean removed.", topicName);
}
}
@VisibleForTesting
public int size() {
return logManager.size();
}
public CompletableFuture