Skip to content

fix #514, call_data_callbacks after shared the data#548

Open
jmorice91 wants to merge 6 commits intomainfrom
514-delay-data-events-in-multi_expose
Open

fix #514, call_data_callbacks after shared the data#548
jmorice91 wants to merge 6 commits intomainfrom
514-delay-data-events-in-multi_expose

Conversation

@jmorice91
Copy link
Contributor

@jmorice91 jmorice91 commented Mar 2, 2025

!!!INSERT YOUR DESCRIPTION HERE!!!

List of things to check before making a PR

Before merging your code, please check the following:

  • you have added a line describing your changes to the Changelog;
  • you have added unit tests for any new or improved feature;
  • In case you updated dependencies, you have checked pdi/docs/CheckList.md
  • you have checked your code format:
    • you have checked that you respect all conventions specified in CONTRIBUTING.md;
    • you have checked that the indentation and formatting conforms to the .clang-format;
    • you have documented with doxygen any new or changed function / class;
  • you have correctly updated the copyright headers:
    • your institution is in the copyright header of every file you (substantially) modified;
    • you have checked that the end-year of the copyright there is the current one;
  • you have updated the AUTHORS file:
    • you have added yourself to the AUTHORS file;
    • if this is a new contribution, you have added it to the AUTHORS file;
  • you have added everything to the user documentation:
    • any new CMake configuration option;
    • any change in the yaml config;
    • any change to the public or plugin API;
    • any other new or changed user-facing feature;
    • any change to the dependencies;
  • you have correctly linked your MR to one or more issues:
    • your MR solves an identified issue;
    • your commit contain the Fix #issue keyword to autoclose the issue when merged.

@jmorice91 jmorice91 linked an issue Mar 2, 2025 that may be closed by this pull request
@jmorice91 jmorice91 marked this pull request as draft March 2, 2025 21:48
@jmorice91 jmorice91 marked this pull request as ready for review March 13, 2025 21:43
@jmorice91 jmorice91 self-assigned this Mar 13, 2025
Copy link
Member

@benoitmartin88 benoitmartin88 left a comment

Choose a reason for hiding this comment

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

Great feature to add. Thanks !
Not much is needed to merge this PR.
I think this feature would require a unit test. Could you add this?

@jmorice91 jmorice91 marked this pull request as draft April 4, 2025 08:43
@jmorice91 jmorice91 force-pushed the 514-delay-data-events-in-multi_expose branch from 656e28b to 3e1d45f Compare April 4, 2025 09:23
@jmorice91 jmorice91 requested a review from JAuriac April 9, 2025 13:27
@jmorice91 jmorice91 marked this pull request as ready for review April 9, 2025 13:27
Copy link
Member

@benoitmartin88 benoitmartin88 left a comment

Choose a reason for hiding this comment

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

Almost ready to merge.
I do have a few questions that need answering concerning error handling, potentially superfluous functions and writing tests in C++.

@jmorice91 jmorice91 marked this pull request as draft May 12, 2025 09:07
@jmorice91 jmorice91 force-pushed the 514-delay-data-events-in-multi_expose branch from f542e39 to 6806742 Compare May 12, 2025 09:18
@jmorice91 jmorice91 requested a review from benoitmartin88 May 12, 2025 09:45
@jmorice91 jmorice91 marked this pull request as ready for review May 12, 2025 09:46
Copy link
Member

@benoitmartin88 benoitmartin88 left a comment

Choose a reason for hiding this comment

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

I think this is almost ready to merge.
Could you make sure the indent and spacing of the modified files is correct ?
Thanks !

Yushan-Wang
Yushan-Wang previously approved these changes Jun 4, 2025
@jmorice91
Copy link
Contributor Author

I think this is almost ready to merge. Could you make sure the indent and spacing of the modified files is correct ? Thanks !

Is it normal that the action indent doesn't catch that?

@jmorice91 jmorice91 requested a review from benoitmartin88 June 5, 2025 10:12
Copy link
Member

@Yushan-Wang Yushan-Wang left a comment

Choose a reason for hiding this comment

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

Ready to merge

@Yushan-Wang
Copy link
Member

@jbigot Could you review this PR please?

Copy link
Member

@jbigot jbigot left a comment

Choose a reason for hiding this comment

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

This is a great submission! My main comment is about moving Var_to_reclaim of the provider side instead of expecting each user to implement it. Overall this is really nice though!

Yushan-Wang
Yushan-Wang previously approved these changes Sep 12, 2025
@jbigot
Copy link
Member

jbigot commented Oct 28, 2025

What's the status for this one?

@jmorice91
Copy link
Contributor Author

What's the status for this one?

It is ready to review.

@jbigot
Copy link
Member

jbigot commented Nov 3, 2025

@Yushan-Wang , @benoitmartin88 , @JAuriac : I'd like a cross review first and then I'll do one. Who has time for one?

@benoitmartin88
Copy link
Member

Je regarde.

Copy link
Member

@benoitmartin88 benoitmartin88 left a comment

Choose a reason for hiding this comment

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

Thank you for this contribution. There are a few changes that are required.

@jmorice91 jmorice91 marked this pull request as draft December 3, 2025 15:26
@jmorice91 jmorice91 force-pushed the 514-delay-data-events-in-multi_expose branch from 0dee087 to 4656252 Compare February 17, 2026 11:30
@jmorice91 jmorice91 force-pushed the 514-delay-data-events-in-multi_expose branch from 4656252 to 352441e Compare February 17, 2026 14:41
@jmorice91 jmorice91 marked this pull request as ready for review February 23, 2026 09:22
#include <pdi/datatype_template.h>
#include <pdi/ref_any.h>

// #include "global_context.h"
Copy link
Member

Choose a reason for hiding this comment

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

remove?

Copy link
Contributor Author

@jmorice91 jmorice91 Feb 24, 2026

Choose a reason for hiding this comment

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

I will be remove in the next commit

Comment on lines +39 to +40
// #include "global_context.h"

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// #include "global_context.h"

* \param[in,out] data the shared data
* \param read whether read access is granted to other references
* \param write whether write access is granted to other references
* \param delayed_callbacks a class that allow to delay trigger_delayed_data_callbacks for a list of a data
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* \param delayed_callbacks a class that allow to delay trigger_delayed_data_callbacks for a list of a data
* \param delayed_callbacks a list of callbacks where the callback for this data will be added, instead of being triggered. So that one can delay the trigger

* \param[in,out] ref a reference to the shared data
* \param read whether the stored reference should have read access
* \param write whether the stored reference should have write access
* \param delayed_callbacks a class that allow to delay trigger_delayed_data_callbacks for a list of a data
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* \param delayed_callbacks a class that allow to delay trigger_delayed_data_callbacks for a list of a data
* \param delayed_callbacks a list of callbacks where the callback for this data will be added, instead of being triggered. So that one can delay the trigger


/** function to call "data_callbacks" for the shared data.
*/
virtual void trigger_delayed_data_callbacks() = 0;
Copy link
Member

Choose a reason for hiding this comment

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

Why is it still required?

Copy link
Contributor Author

@jmorice91 jmorice91 Feb 25, 2026

Choose a reason for hiding this comment

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

We need that because m_context[element_name.c_str()] is a data_descriptor in Delayed_data_callbacks

Do you want to remove trigger_delayed_data_callbacks() in the class data_descriptor_impl and put this function inside class PDI_EXPORT Delayed_data_callbacks?

I want to keep this function inside data_descriptor_impl because I don't want to change m_refs outside this class

/// References to the values of this descriptor
std::stack<std::unique_ptr<Ref_holder>> m_refs;


class PDI_EXPORT Delayed_data_callbacks
{
/// friend class Global_context;
Copy link
Member

Choose a reason for hiding this comment

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

What does this comment mean?

m_context.logger().error("Error in the destructor of Delayed_data_callbacks, {}", e.what());
} else {
// No exception is throwing. Throw an error.
m_context.logger().error("Error in the destructor of Delayed_data_callbacks.");
Copy link
Member

Choose a reason for hiding this comment

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

since you rethrow. I wouldn't print anything in that case:

Suggested change
m_context.logger().error("Error in the destructor of Delayed_data_callbacks.");

m_context.logger().error("Error in the destructor of Delayed_data_callbacks.");
} else {
// No exception is throwing. Throw an error.
m_context.logger().error("Error in the destructor of Delayed_data_callbacks.");
Copy link
Member

Choose a reason for hiding this comment

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

same as above

Suggested change
m_context.logger().error("Error in the destructor of Delayed_data_callbacks.");

// (example: error in the config.yml for a plugin, error due to external library incompatibility)
~Delayed_data_callbacks() noexcept(false)
{
try {
Copy link
Member

Choose a reason for hiding this comment

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

why not move the try one step up?

Comment on lines +106 to +121
void trigger()
try {
int i = 0;
size_t number_of_elements = m_datanames.size();
for (auto&& element_name: m_datanames) {
m_context.logger().trace("Trigger data callback `{}' ({}/{})", element_name.c_str(), ++i, number_of_elements);
m_context[element_name.c_str()].trigger_delayed_data_callbacks();
}
this->cancel(); // clear the m_datanames
} catch (Error& e) {
this->cancel(); // clear the m_datanames
throw Error(e.status(), "Error in trigger data callback: `{}'", e.what());
} catch (...) {
this->cancel(); // clear the m_datanames
throw;
}
Copy link
Member

Choose a reason for hiding this comment

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

When an exception is thrown, we'd like the events not yet triggered to remain in the list of events to trigger.

Suggested change
void trigger()
try {
int i = 0;
size_t number_of_elements = m_datanames.size();
for (auto&& element_name: m_datanames) {
m_context.logger().trace("Trigger data callback `{}' ({}/{})", element_name.c_str(), ++i, number_of_elements);
m_context[element_name.c_str()].trigger_delayed_data_callbacks();
}
this->cancel(); // clear the m_datanames
} catch (Error& e) {
this->cancel(); // clear the m_datanames
throw Error(e.status(), "Error in trigger data callback: `{}'", e.what());
} catch (...) {
this->cancel(); // clear the m_datanames
throw;
}
void trigger()
{
int i = 0;
size_t number_of_elements = m_datanames.size();
while ( ! m_datanames.empty() ) {
auto&& element_name = m_datanames.back();
m_context.logger().trace("Trigger data callback `{}' ({}/{})", element_name, ++i, number_of_elements);
m_context[element_name].trigger_delayed_data_callbacks();
m_datanames.pop_back()
}
}


/** A structure to reclaim the datas properly in case of error
*/
struct Var_to_reclaim {
Copy link
Member

Choose a reason for hiding this comment

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

Why is this class still required? Isn't Delayed_data_callbacks enough?

Copy link
Contributor Author

@jmorice91 jmorice91 Feb 25, 2026

Choose a reason for hiding this comment

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

These two classes are defined with the same list of dataname in some sense.
(It depends only if we have an error after delayed_callbacks.add_dataname(m_name);
in void* Data_descriptor_impl::share) -> good catch.

Remark:
In PDI_share, the destruction of the object Delayed_data_callbacks execute event on_data in this implementation.
The class Var_to_reclaim is used to call PDI_reclaim the data in PDI_multi_expose.

So if we want to have only 1 class:

  • need to rename the class Delayed_data_callbacks -> name ???
  • add a member to this class to know if we are in the multi_expose case to have two version of destructor:
  1. dtor1 : call trigger()
  2. dtor2: call trigger() + reclaim the variables.
  • Perhaps add a member to this class to know if we call trigger() before.
  • don't remove element in the list of the dataname in trigger()

Is it what you want to implement? we can discuss if you want.

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.

Delay data events in multi_expose to when the last data is exposed

4 participants