Package org.apache.pulsar.compaction
Class AbstractTwoPhaseCompactor<T>
java.lang.Object
org.apache.pulsar.compaction.Compactor
org.apache.pulsar.compaction.AbstractTwoPhaseCompactor<T>
- Direct Known Subclasses:
EventTimeOrderCompactor,PublishingOrderCompactor
Compaction will go through the topic in two passes. The first pass
selects latest offset for each key in the topic. Then the second pass
writes these values to a ledger.
The two passes are required to avoid holding the payloads of each of the latest values in memory, as the payload can be many orders of magnitude larger than a message id.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final intprotected final Durationprotected final booleanFields inherited from class org.apache.pulsar.compaction.Compactor
bk, COMPACTED_TOPIC_LEDGER_PROPERTY, COMPACTION_SUBSCRIPTION, conf, mxBean, pulsar, scheduler -
Constructor Summary
ConstructorsConstructorDescriptionAbstractTwoPhaseCompactor(ServiceConfiguration conf, org.apache.pulsar.client.api.PulsarClient pulsar, BookKeeper bk, ScheduledExecutorService scheduler) -
Method Summary
Modifier and TypeMethodDescriptionprotected CompletableFuture<Void>protected abstract booleancompactBatchMessage(String topic, Map<String, T> latestForKey, RawMessage m, org.apache.pulsar.common.api.proto.MessageMetadata metadata, org.apache.pulsar.client.api.MessageId id) protected abstract booleancompactMessage(String topic, Map<String, T> latestForKey, RawMessage m, org.apache.pulsar.common.api.proto.MessageMetadata metadata, org.apache.pulsar.client.api.MessageId id) protected CompletableFuture<LedgerHandle>createLedger(BookKeeper bk, Map<String, byte[]> metadata) protected CompletableFuture<Void>deleteLedger(BookKeeper bk, LedgerHandle lh) protected CompletableFuture<Long>doCompaction(RawReader reader, BookKeeper bk) extractKeyAndSize(RawMessage m, org.apache.pulsar.common.api.proto.MessageMetadata msgMetadata) longprotected Optional<RawMessage>rebatchMessage(String topic, RawMessage msg, org.apache.pulsar.common.api.proto.MessageMetadata metadata, BiPredicate<String, org.apache.pulsar.client.api.MessageId> filter, boolean retainNullKey) toLatestMessageIdForKey(Map<String, T> latestForKey)
-
Field Details
-
MAX_OUTSTANDING
protected static final int MAX_OUTSTANDING- See Also:
-
phaseOneLoopReadTimeout
-
topicCompactionRetainNullKey
protected final boolean topicCompactionRetainNullKey
-
-
Constructor Details
-
AbstractTwoPhaseCompactor
public AbstractTwoPhaseCompactor(ServiceConfiguration conf, org.apache.pulsar.client.api.PulsarClient pulsar, BookKeeper bk, ScheduledExecutorService scheduler)
-
-
Method Details
-
toLatestMessageIdForKey
-
compactMessage
protected abstract boolean compactMessage(String topic, Map<String, T> latestForKey, RawMessage m, org.apache.pulsar.common.api.proto.MessageMetadata metadata, org.apache.pulsar.client.api.MessageId id) -
compactBatchMessage
protected abstract boolean compactBatchMessage(String topic, Map<String, T> latestForKey, RawMessage m, org.apache.pulsar.common.api.proto.MessageMetadata metadata, org.apache.pulsar.client.api.MessageId id) -
doCompaction
- Specified by:
doCompactionin classCompactor
-
createLedger
-
deleteLedger
-
closeLedger
-
extractKeyAndSize
protected org.apache.commons.lang3.tuple.Pair<String,Integer> extractKeyAndSize(RawMessage m, org.apache.pulsar.common.api.proto.MessageMetadata msgMetadata) -
rebatchMessage
protected Optional<RawMessage> rebatchMessage(String topic, RawMessage msg, org.apache.pulsar.common.api.proto.MessageMetadata metadata, BiPredicate<String, org.apache.pulsar.client.api.MessageId> filter, boolean retainNullKey) throws IOException- Throws:
IOException
-
getPhaseOneLoopReadTimeoutInSeconds
public long getPhaseOneLoopReadTimeoutInSeconds()
-