Skip to content

Support Create Partitions - #623

Open
BlueCollarChris wants to merge 1 commit into
kafka4beam:masterfrom
BlueCollarChris:master
Open

Support Create Partitions#623
BlueCollarChris wants to merge 1 commit into
kafka4beam:masterfrom
BlueCollarChris:master

Conversation

@BlueCollarChris

@BlueCollarChris BlueCollarChris commented Mar 20, 2025

Copy link
Copy Markdown

Adds the ability to create partitions for an existing topic (brod:create_partitions/3,4), exposing create_partitions from the underlying kafka_protocol.

Adds an optional client config metadata_refresh_interval_seconds: when set, the client starts a ticker in the brod_client process that periodically refreshes metadata for the topics it has producers running for, so producers are started automatically for newly discovered partitions (via the existing maybe_start_partition_producer path added in #636).

Reworked per review: the brod_partitions_sync module is gone in favor of the in-client ticker, the branch is rebased on current master with the formatting noise dropped, and brod_SUITE gains t_auto_start_producers_for_new_partitions which creates a topic, starts a producer, adds a partition, and asserts the new partition producer starts automatically.

@BlueCollarChris

Copy link
Copy Markdown
Author

Working on tests still but posting for initial feedback

@zmstone

zmstone commented Mar 20, 2025

Copy link
Copy Markdown
Contributor

thank you for the PR @BlueCollarChris
could you add an entry in CHANGELOG.md

Comment thread src/brod_client.erl Outdated
@BlueCollarChris

Copy link
Copy Markdown
Author

Just seeing the comments now and will get back to you on Monday. I had been exploring a different route locally where the sync is done outside the client in a linked genserver. I wasn't sure if the sync process were to block the client would be disrupted from handling other requests. I'll see about getting those changes up shortly.

Comment thread src/brod_partitions_sync.erl Outdated
interval = Interval
} = State
) ->
sync_partitions(Client, Sup, Config),

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ensure the new partitions get a producer but then we need to tell the client to update the metadata so it can use the new partition.

Comment thread src/brod_producers_sup.erl Outdated
brod_supervisor3:start_child(SupPid, Spec).

%% @doc Dynamically start a per partition producer
-spec start_producer(pid(), pid(), brod:topic(), non_neg_integer(), brod:producer_config()) ->

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

variant for starting just the partition producer with the correct child spec

@BlueCollarChris

Copy link
Copy Markdown
Author

@zmstone got the update in I mentioned over the weekend. Is there a specific formatter you recommend looks like the one for my IDE formatted some stuff showing more changes than were there previously. I did make the change to start the partition producer under the brod_supervisor3 as mentioned in your previous comment. Working on the tests for the brod_partitions_sync module still.

@BlueCollarChris
BlueCollarChris requested a review from zmstone March 24, 2025 16:27
@zmstone

zmstone commented Apr 22, 2025

Copy link
Copy Markdown
Contributor

Hi @BlueCollarChris
Thank you for the PR and sorry for the slow review.

About code format: we use https://github.com/WhatsApp/erlfmt
example for ref:
https://github.com/kafka4beam/brod-cli/blob/f8a2784f4ffb7aa70bf8006c2b519ca12991c4f7/rebar.config#L7-L10

Possible to leave code reformat out in this PR? it makes review easier.

Comment thread src/brod_partitions_sync.erl Outdated
@BlueCollarChris

Copy link
Copy Markdown
Author

I have been completely swamped but will get to updating the formatting of this very soon, sorry for the delay

@zmstone

zmstone commented Oct 2, 2025

Copy link
Copy Markdown
Contributor

thanks. there are some conflicts.
could you rebase ?

@BlueCollarChris

Copy link
Copy Markdown
Author

Working on the formatting at this point to remove the changes and conform the new module to it

@BlueCollarChris

Copy link
Copy Markdown
Author

@zmstone This is now ready. I have removed the formatting changes from the code that was causing the delay from earlier.

Comment thread src/brod_client.erl Outdated
%%% allout-layout: t
%%% erlang-indent-level: 2
%%% End:
%%% End: No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: please revert this.

Comment thread src/brod_producers_sup.erl Outdated
%%% allout-layout: t
%%% erlang-indent-level: 2
%%% End:
%%% End: No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please revert this change

Comment thread test/brod_SUITE.erl

%% Test cases
-export([ t_create_delete_topics/1
-export([ t_create_update_delete_topics/1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you add another case which starts producers for a topic, then create new partitions, then assert that partition producer is started automatically?

Comment thread src/brod_partitions_sync.erl Outdated
%% @doc A `brod_partitions_sync' is a `gen_server' that is responsible for fetching
%% the latest partition counts for a client and ensuring external changes to partitions
%% are propogated to the clients and starts a producer for the partition if not present
-module(brod_partitions_sync).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is maybe no need for this module.
we can start a timer (ticker) in brod_client process to trigger a periodic metadata refresh.

brod_client will automatically start the producers for newly discovered partitions.

brod/src/brod_client.erl

Lines 638 to 643 in 674ae4d

ok = maybe_start_partition_producer(
filter_topics(TopicsMetadata),
brod_producers_sup:count_started_children(ProducersSup),
Topics,
ProducersSup
),

Add brod:create_partitions/3,4 to add partitions to an existing topic.

Add optional client config metadata_refresh_interval_seconds: when set,
the client periodically refreshes metadata for the topics it has
producers running for, so producers are started automatically for
newly discovered partitions.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@BlueCollarChris

Copy link
Copy Markdown
Author

Finally got around to closing this out, hope it is what was expected. Verified our forked version through my companies tests that the alt approach recommended handles our use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants