Skip to content

MINIFICPP-1288 - FlowController start/load refactor#890

Closed
hunyadi-dev wants to merge 11 commits intoapache:mainfrom
hunyadi-dev:MINIFICPP-1288_FlowController_refactor_start_method
Closed

MINIFICPP-1288 - FlowController start/load refactor#890
hunyadi-dev wants to merge 11 commits intoapache:mainfrom
hunyadi-dev:MINIFICPP-1288_FlowController_refactor_start_method

Conversation

@hunyadi-dev
Copy link
Contributor

@hunyadi-dev hunyadi-dev commented Sep 2, 2020

It is easiest to review this PR on a per-commit basis.

The FlowController methods: start, stop, load, unload (and maybe even waitUnload), were strongly coupled and were controlled through FlowController states that made it difficult to argue about what goes on in each of them.

load had two versions with only minor differences, one reload (with a few extra steps) and one non-reload. The version that did the reload was only called during applyConfiguration, so I moved the extra behaviour required there (and renamed the related functions accordingly to prove there were no other instances of calling reload).

load was also changing the state of initialized_ read by only itself and start, but it is easy to argue that load is never called twice and start is never called without a preceeding load, proving this variable clutter.

@hunyadi-dev hunyadi-dev force-pushed the MINIFICPP-1288_FlowController_refactor_start_method branch from 876798a to 2a4e8ab Compare September 2, 2020 07:41
@hunyadi-dev hunyadi-dev force-pushed the MINIFICPP-1288_FlowController_refactor_start_method branch from 2a4e8ab to 02aff17 Compare September 7, 2020 09:08
Copy link
Contributor

@arpadboda arpadboda left a comment

Choose a reason for hiding this comment

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

Most looks good, added some comments.

Copy link
Member

@szaszm szaszm left a comment

Choose a reason for hiding this comment

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

Since the requirement of "one has to call load before start" is not documented anywhere, I would restore the initialized_ variable to prevent invalid usage of FlowController.
I fell into this trap of only calling stop/start instead of stop,unload/load,start while working on #875

Comment on lines +326 to +328
timer_scheduler_ = std::make_shared<TimerDrivenSchedulingAgent>(NonNullControllerServiceProviderPtr(this), provenance_repo_, flow_file_repo_, content_repo_, configuration_, thread_pool_);
event_scheduler_ = std::make_shared<EventDrivenSchedulingAgent>(NonNullControllerServiceProviderPtr(this), provenance_repo_, flow_file_repo_, content_repo_, configuration_, thread_pool_);
cron_scheduler_ = std::make_shared<CronDrivenSchedulingAgent>(NonNullControllerServiceProviderPtr(this), provenance_repo_, flow_file_repo_, content_repo_, configuration_, thread_pool_);
Copy link
Member

@szaszm szaszm Sep 7, 2020

Choose a reason for hiding this comment

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

Consider using gsl::make_not_null and relying on implicit conversion to base class pointer.

Suggested change
timer_scheduler_ = std::make_shared<TimerDrivenSchedulingAgent>(NonNullControllerServiceProviderPtr(this), provenance_repo_, flow_file_repo_, content_repo_, configuration_, thread_pool_);
event_scheduler_ = std::make_shared<EventDrivenSchedulingAgent>(NonNullControllerServiceProviderPtr(this), provenance_repo_, flow_file_repo_, content_repo_, configuration_, thread_pool_);
cron_scheduler_ = std::make_shared<CronDrivenSchedulingAgent>(NonNullControllerServiceProviderPtr(this), provenance_repo_, flow_file_repo_, content_repo_, configuration_, thread_pool_);
timer_scheduler_ = std::make_shared<TimerDrivenSchedulingAgent>(gsl::make_not_null(this), provenance_repo_, flow_file_repo_, content_repo_, configuration_, thread_pool_);
event_scheduler_ = std::make_shared<EventDrivenSchedulingAgent>(gsl::make_not_null(this), provenance_repo_, flow_file_repo_, content_repo_, configuration_, thread_pool_);
cron_scheduler_ = std::make_shared<CronDrivenSchedulingAgent>(gsl::make_not_null(this), provenance_repo_, flow_file_repo_, content_repo_, configuration_, thread_pool_);

Copy link
Contributor Author

@hunyadi-dev hunyadi-dev Sep 7, 2020

Choose a reason for hiding this comment

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

What is the advantake of using make_not_null? It does nothing, does it?

Update:
I see what you mean now.

@hunyadi-dev
Copy link
Contributor Author

Since the requirement of "one has to call load before start" is not documented anywhere, I would restore the initialized_ variable to prevent invalid usage of FlowController.
I fell into this trap of only calling stop/start instead of stop,unload/load,start while working on #875

I see what you mean, but I disagree. I would definitely avoid adding states like this to an object. I found it already quite a task to decipher in what state can we reach each of the member functions. How about either of these options:

  1. I can make the FlowController a state machine with well defined transitions between states
  2. I can add checks to the start method that ensure that the members set in load are indeed set.

@szaszm
Copy link
Member

szaszm commented Sep 7, 2020

I see what you mean, but I disagree. I would definitely avoid adding states like this to an object. I found it already quite a task to decipher in what state can we reach each of the member functions. How about either of these options:
1. I can make the FlowController a state machine with well defined transitions between states
2. I can add checks to the start method that ensure that the members set in load are indeed set.

I don't really understand what you mean by making FlowController a state machine or checking members, but in either case, if you can make it hard or impossible to use FlowController incorrectly, that would be a big plus in my opinion.

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.

3 participants