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

Copier context #196

Merged
merged 10 commits into from
Aug 25, 2020
Merged

Copier context #196

merged 10 commits into from
Aug 25, 2020

Conversation

massdosage
Copy link
Contributor

Fixes #195

This PR introduces a CopierContext class to hold the values that were being passed to the CopierFactory before, and then adds a TableReplication to this which in turns holds the additional values that were requested in the issue (source database and table names). This allows us to add more values to CopierContext in the past without breaking backwards compatibility which is the situation we're currently in due to the interface methods directly containing the values as arguments.

The changes in this PR are currently backwards-compatible by using a default method in the CopierFactory interface but I'll add some comments on this as another option would be to make a backwards incompatible change as it's quite easy to resolve downstream.

@massdosage massdosage requested a review from a team August 21, 2020 15:47
}

/**
* @deprecated As of release 16.3.0, replaced by {@link #newInstance(CopierContext)}.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of deprecating these we could remove them and then just have the method above and clearly document in the CHANGELOG what the required change is for this. It's basically just updating any custom CopierFactory implementations to implement the new method and pull the values they need out of the CopierContext instead of having them passed as method arguments. Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd still rather deprecate it and, in case, have it removed later on.

Copy link
Contributor

Choose a reason for hiding this comment

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

deprecate and remove is the more friendly way, I'm ok either way though it's not a big change to do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, let's go with a 16.3.0 release that is backwards compatible, I'll update the changelog accordingly.

String replicaDatabaseName,
String replicaTableName,
String replicaTableLocation) {
Replica replica) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice simplification.

Copy link
Contributor

@nvitucci nvitucci left a comment

Choose a reason for hiding this comment

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

It looks good to me. The TableReplication simplifies the code further.
I would still deprecate the "old" method rather then removing it, and possibly remove it in a later release.


import com.hotels.bdp.circustrain.api.conf.TableReplication;

public class CopierContext {
Copy link
Contributor

Choose a reason for hiding this comment

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

thoughts on making this immutable? Is there a risk of a copier accidentally change one of these fields which might affect further copiers in the chain?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I thought about making this immutable and having a builder instead of this big constructor but this was quicker and easier to do in terms of updating the existing code. However the TableReplication isn't immutable so we'd only be halfway there unless I looked into that too (not sure that's really possible as it maps directly to the config which needs to set values).

If we didn't want to use a builder I could add 2 more constructors which allow the TableReplication to be passed in too and then I make immutable copies of the List and Map member variables and we live with TableReplication not being immutable.

I can do either (or if someone has better suggestions) if we think it's worth it?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think since this is a new one we make the good example and make it immutable. I'm ok leaving TableReplication for another time as that will be backward incompatible change I guess.

Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't there any place where the context may actually need to be updated?

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah I was also thinking about that, not sure what we want to achieve. The order in which copiers are run is guaranteed by spring so you could have a copier relying on another copier updating the context. If that's they way we want to go then obviously we don't want to make it immutable. Could argue either way I guess :)

Copy link
Contributor

Choose a reason for hiding this comment

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

the class needs to be final

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does! Good spot!

Copy link
Contributor

Choose a reason for hiding this comment

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

and because TableReplication isn't immutable you need to copy it as well. Path also isn't :/ it's a pandemic. Not sure how much you want to open that can of worms. I can live with a not fully immutable class for the sake of pragmatism.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, you're right, I think we either leave as it is now and live with a decent attempt but TableReplication and Path are mutable or we just roll the whole set of immutable changes back.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm ok with this.

@massdosage massdosage merged commit 6c45be9 into master Aug 25, 2020
@massdosage massdosage deleted the copier-context branch August 25, 2020 07:45
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.

Make more configuration values available to Copiers
3 participants