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

Refactor code related to crash groups and linking mechanism #574

Merged
merged 16 commits into from
Aug 22, 2023

Conversation

FelonEkonom
Copy link
Member

@FelonEkonom FelonEkonom added the no-changelog This label has to be added if changes from the PR are not meant to be placed in the CHANGELOG.md label Jun 30, 2023
@FelonEkonom FelonEkonom force-pushed the refactor-crash-groups branch 5 times, most recently from a389db0 to 95b5d23 Compare July 11, 2023 15:36
@FelonEkonom FelonEkonom force-pushed the refactor-crash-groups branch from 95b5d23 to 233b0d2 Compare July 11, 2023 15:36
@FelonEkonom FelonEkonom marked this pull request as ready for review July 11, 2023 16:22
@FelonEkonom FelonEkonom requested a review from mat-hek as a code owner July 11, 2023 16:22
@FelonEkonom FelonEkonom force-pushed the refactor-crash-groups branch from 92e500a to ed3c26f Compare July 18, 2023 12:47
@FelonEkonom FelonEkonom force-pushed the refactor-crash-groups branch from ed3c26f to 809f17f Compare July 18, 2023 12:49
@@ -653,45 +653,32 @@ defmodule Membrane.Core.Parent.ChildLifeController do
end

defp do_handle_child_death(child_name, :normal, state) do
Copy link
Member

Choose a reason for hiding this comment

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

this and the next clause became quite similar, I'd consider merging them


@spec handle_crash_group_member_death(Child.name(), CrashGroup.t(), any(), Parent.state()) ::
Parent.state()
def handle_crash_group_member_death(child_name, crash_group_data, reason, state)
Copy link
Member

Choose a reason for hiding this comment

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

this has so many clauses, can we make it a bit less verbose?

Comment on lines 363 to 369
defp merge_pad_direction_data(pad_data, metadata, state) do
merge_pad_data(pad_data, &init_pad_direction_data(&1, metadata, state))
end

defp merge_pad_mode_data(pad_data, props, other_info, state) do
merge_pad_data(pad_data, &init_pad_mode_data(&1, props, other_info, state))
end
Copy link
Member

Choose a reason for hiding this comment

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

These add another level of complexity, which is one level too much IMO. If you don't like passing a function to merge_pad_data, I'd rather remove it and rename each init_pad_*_data function to merge_pad_*_data and explicitly call Map.merge there.

@FelonEkonom FelonEkonom force-pushed the refactor-crash-groups branch from acef791 to cfa54e8 Compare July 19, 2023 14:58
@FelonEkonom FelonEkonom force-pushed the refactor-crash-groups branch from cf3ab1b to d3a16ea Compare July 20, 2023 12:02
@FelonEkonom FelonEkonom requested a review from mat-hek July 20, 2023 12:03
@FelonEkonom FelonEkonom requested a review from varsill July 25, 2023 09:27
Comment on lines 141 to 142
if pad_info.direction != :input,
do: raise("pad direction #{inspect(pad_info.direction)} is wrong")
Copy link
Contributor

Choose a reason for hiding this comment

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

is it even possible? If so, why don't we move it to the pattern match?

@@ -137,17 +130,18 @@ defmodule Membrane.Core.Element.PadController do
end
end

defp do_handle_link(:input, endpoint, other_endpoint, info, link_props, state) do
defp do_handle_link(:input, endpoint, other_endpoint, pad_info, link_props, state) do
Copy link
Contributor

Choose a reason for hiding this comment

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

perhaps we could "resolve" the names (endpoint -> input_endpoint etc.)?

Copy link
Contributor

Choose a reason for hiding this comment

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

the same applies for the do_handle_link(:output, ...)

Comment on lines 333 to 343
state =
state.pads_data
|> Map.values()
|> Enum.filter(&(&1.direction != data.direction and &1.flow_control == :auto))
|> Enum.reduce(state, fn other_data, state ->
PadModel.update_data!(state, other_data.ref, :associated_pads, &[data.ref | &1])
|> Enum.filter(&(&1.direction != pad_data.direction and &1.flow_control == :auto))
|> Enum.reduce(state, fn opposite_pad_data, state ->
PadModel.update_data!(
state,
opposite_pad_data.ref,
:associated_pads,
&[pad_data.ref | &1]
)
Copy link
Contributor

Choose a reason for hiding this comment

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

[NIT] I would opt for moving that part of code to some separate function, e.g. update_associated_pads or something like that.


# adding crash group to state
state =
if options.crash_group_mode != nil do
if options.crash_group_mode != nil or Map.has_key?(state.crash_groups, options.group) do
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure I get it - shouldn't it be: if options.crash_group_mode != nil and (not Map.has_key?(state.crash_groups, options.group))
?

end
end

defp trigger_crash_group(crash_initiator, %CrashGroup{} = group, state) do
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not the biggest fan of the trigger_crash_group name - I would opt at least for trigger_crash_group_crash, but it might sound funny :D
Perhaps you have some better alternative?

Copy link
Contributor

Choose a reason for hiding this comment

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

and when it comes to triggered? - I would rename it to crash_triggered? or something like that

@FelonEkonom FelonEkonom force-pushed the refactor-crash-groups branch from d7d57aa to 332a724 Compare July 28, 2023 13:13
Copy link
Member

@mat-hek mat-hek left a comment

Choose a reason for hiding this comment

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

Looks good 👍

@FelonEkonom FelonEkonom requested review from varsill and mat-hek August 21, 2023 14:13
test/membrane/core/element_test.exs Show resolved Hide resolved
@@ -130,10 +130,10 @@ defmodule Membrane.Core.ElementTest do
%Endpoint{pad_spec: :output, pad_ref: :output, pad_props: %{options: []}, child: :this},
output_other_endpoint,
%{
other_info: other_info,
# other_info: other_info,
Copy link
Contributor

Choose a reason for hiding this comment

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

;)

[Child.name()],
Parent.state()
) :: Parent.state()
def extend_crash_group(group_name, _mode, children, state) do
Copy link
Contributor

Choose a reason for hiding this comment

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

I would remove mode argument here

Suggested change
def extend_crash_group(group_name, _mode, children, state) do
def extend_crash_group(group_name, children, state) do

@FelonEkonom FelonEkonom requested a review from varsill August 22, 2023 14:35
@FelonEkonom FelonEkonom merged commit 68ab243 into master Aug 22, 2023
@FelonEkonom FelonEkonom deleted the refactor-crash-groups branch August 22, 2023 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-changelog This label has to be added if changes from the PR are not meant to be placed in the CHANGELOG.md
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants