Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for cooperative partition reassignment strategy #198

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/Kafka/Consumer/Callbacks.hs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ setRebalanceCallback f k e pls = do
case e of
KafkaResponseError RdKafkaRespErrAssignPartitions -> do
f k (RebalanceBeforeAssign assignment)
void $ rdKafkaAssign kptr pls
protocol <- rdKafkaRebalanceProtocol kptr
if protocol == "COOPERATIVE"
then void $ rdKafkaIncrementalAssign kptr pls
else void $ rdKafkaAssign kptr pls

mbq <- getRdMsgQueue $ getKafkaConf k
case mbq of
Expand All @@ -84,6 +87,9 @@ setRebalanceCallback f k e pls = do

KafkaResponseError RdKafkaRespErrRevokePartitions -> do
f k (RebalanceBeforeRevoke assignment)
void $ newForeignPtr_ nullPtr >>= rdKafkaAssign kptr
protocol <- rdKafkaRebalanceProtocol kptr
if protocol == "COOPERATIVE"
then void $ rdKafkaIncrementalUnassign kptr pls
else void $ newForeignPtr_ nullPtr >>= rdKafkaAssign kptr
f k (RebalanceRevoke assignment)
x -> error $ "Rebalance: UNKNOWN response: " <> show x
10 changes: 10 additions & 0 deletions src/Kafka/Internal/RdKafka.chs
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,9 @@ pollRdKafkaConsumer k t = do
{`RdKafkaTPtr', `RdKafkaTopicPartitionListTPtr'}
-> `RdKafkaRespErrT' cIntToEnum #}

{#fun rd_kafka_rebalance_protocol as ^
{`RdKafkaTPtr'} -> `String' #}

{#fun rd_kafka_assignment as rdKafkaAssignment'
{`RdKafkaTPtr', alloca- `Ptr RdKafkaTopicPartitionListT' peekPtr* }
-> `RdKafkaRespErrT' cIntToEnum #}
Expand Down Expand Up @@ -1101,6 +1104,13 @@ rdKafkaMessageProduceVa kafkaPtr vts = withArrayLen vts $ \i arrPtr -> do
{#fun rd_kafka_abort_transaction as rdKafkaAbortTransaction
{`RdKafkaTPtr', `Int'} -> `RdKafkaErrorTPtr' #}

{#fun rd_kafka_incremental_assign as ^
{`RdKafkaTPtr', `RdKafkaTopicPartitionListTPtr'} -> `RdKafkaErrorTPtr' #}

{#fun rd_kafka_incremental_unassign as ^
{`RdKafkaTPtr', `RdKafkaTopicPartitionListTPtr'}
-> `RdKafkaErrorTPtr' #}

{#fun rd_kafka_consumer_group_metadata as rdKafkaConsumerGroupMetadata
{`RdKafkaTPtr'} -> `Ptr ()' #}

Expand Down
Loading