Package org.apache.pulsar.broker.service
Class HashRangeAutoSplitStickyKeyConsumerSelector
java.lang.Object
org.apache.pulsar.broker.service.HashRangeAutoSplitStickyKeyConsumerSelector
- All Implemented Interfaces:
StickyKeyConsumerSelector
public class HashRangeAutoSplitStickyKeyConsumerSelector
extends Object
implements StickyKeyConsumerSelector
This is a consumer selector based fixed hash range.
1.Each consumer serves a fixed range of hash value
2.The whole range of hash value could be covered by all the consumers.
3.Once a consumer is removed, the left consumers could still serve the whole range.
Initializing with a fixed hash range, by default 2 >> 15.
First consumer added, hash range looks like:
0 -< 65536(consumer-1)
Second consumer added, will find a biggest range to split:
0 -< 32768(consumer-2) -< 65536(consumer-1)
While a consumer removed, The range for this consumer will be taken over
by other consumer, consumer-2 removed:
0 -< 65536(consumer-1)
In this approach use skip list map to maintain the hash range and consumers.
Select consumer will return the ceiling key of message key hashcode % range size.
-
Field Summary
Fields inherited from interface org.apache.pulsar.broker.service.StickyKeyConsumerSelector
DEFAULT_RANGE_SIZE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddConsumer(Consumer consumer) Add a new consumer.Get key hash ranges handled by each consumer.voidremoveConsumer(Consumer consumer) Remove the consumer.select(int hash) Select a consumer by hash.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.pulsar.broker.service.StickyKeyConsumerSelector
select
-
Constructor Details
-
HashRangeAutoSplitStickyKeyConsumerSelector
public HashRangeAutoSplitStickyKeyConsumerSelector() -
HashRangeAutoSplitStickyKeyConsumerSelector
public HashRangeAutoSplitStickyKeyConsumerSelector(int rangeSize)
-
-
Method Details
-
addConsumer
Description copied from interface:StickyKeyConsumerSelectorAdd a new consumer.- Specified by:
addConsumerin interfaceStickyKeyConsumerSelector- Parameters:
consumer- new consumer- Throws:
BrokerServiceException.ConsumerAssignException
-
removeConsumer
Description copied from interface:StickyKeyConsumerSelectorRemove the consumer.- Specified by:
removeConsumerin interfaceStickyKeyConsumerSelector- Parameters:
consumer- consumer to be removed
-
select
Description copied from interface:StickyKeyConsumerSelectorSelect a consumer by hash.- Specified by:
selectin interfaceStickyKeyConsumerSelector- Parameters:
hash- hash corresponding to sticky key- Returns:
- consumer
-
getConsumerKeyHashRanges
Description copied from interface:StickyKeyConsumerSelectorGet key hash ranges handled by each consumer.- Specified by:
getConsumerKeyHashRangesin interfaceStickyKeyConsumerSelector- Returns:
- A map where key is a consumer name and value is list of hash range it receiving message for.
-