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 registerRepository method #108788

Merged
merged 2 commits into from
May 17, 2024

Conversation

mhl-b
Copy link
Contributor

@mhl-b mhl-b commented May 17, 2024

This PR is a syntactic change for registerRepository in RepositoriesService.
I use SubscribableListener to display order of events and reduce boilerplate
code around failures delegation listener.delegateFailureAndWrap.

It's a part of larger change for verification logic, which should take advantage
of this "sequential" version of code. #108531

@elasticsearchmachine elasticsearchmachine added v8.15.0 needs:triage Requires assignment of a team area label labels May 17, 2024
@mhl-b mhl-b added >non-issue :Distributed/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs Team:Distributed Meta label for distributed team and removed needs:triage Requires assignment of a team area label labels May 17, 2024
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-distributed (Team:Distributed)

Copy link
Contributor

@DaveCTurner DaveCTurner left a comment

Choose a reason for hiding this comment

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

Much better. I left some suggestions but nothing substantial

Comment on lines 164 to 167
.<Void>newForked(validationStep -> {
validateRepositoryCanBeCreated(request);
validationStep.onResponse(null);
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Technically unnecessary, but using ActionListener.completeWith makes it more obvious to the casual reader that this listener is always completed:

Suggested change
.<Void>newForked(validationStep -> {
validateRepositoryCanBeCreated(request);
validationStep.onResponse(null);
})
.<Void>newForked(validationStep -> ActionListener.completeWith(validationStep, () -> {
validateRepositoryCanBeCreated(request);
return null;
}))

Comment on lines 204 to 208
publicationStep.addListener(clusterUpdateStep.delegateFailureAndWrap((ignored1, changed) -> {
acknowledgementStep.addListener(clusterUpdateStep.delegateFailureAndWrap((ignored2, ack) -> {
clusterUpdateStep.onResponse(new RegisterRepositoryTaskResult(ack, changed));
}));
}));
Copy link
Contributor

Choose a reason for hiding this comment

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

Best not to capture the listener in the lambdas (probably doesn't matter here, we're capturing other things, but still good practice). Also delegateFailure(onResponse(...)) is just map(...) (the AndWrap bit shouldn't matter here).

Suggested change
publicationStep.addListener(clusterUpdateStep.delegateFailureAndWrap((ignored1, changed) -> {
acknowledgementStep.addListener(clusterUpdateStep.delegateFailureAndWrap((ignored2, ack) -> {
clusterUpdateStep.onResponse(new RegisterRepositoryTaskResult(ack, changed));
}));
}));
publicationStep.addListener(
clusterUpdateStep.delegateFailureAndWrap(
(clusterUpdateStep1, changed) -> acknowledgementStep.addListener(
clusterUpdateStep1.map(ack -> new RegisterRepositoryTaskResult(ack, changed))
)
)
);

}
})
// When verification has completed, get the repository data for the first time
.<RepositoryData>andThen((getRepositoryDataStep, ignored) -> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: unnecessary {...} block, this can just be an expression lambda.

Suggested change
.<RepositoryData>andThen((getRepositoryDataStep, ignored) -> {
.<RepositoryData>andThen((getRepositoryDataStep, ignored) ->

);
})
// When the repository metadata is ready, update the repository UUID stored in the cluster state, if available
.<Void>andThen((updateRepoUuidStep, repositoryData) -> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: unnecessary {...} block, this can just be an expression lambda.

Suggested change
.<Void>andThen((updateRepoUuidStep, repositoryData) -> {
.<Void>andThen((updateRepoUuidStep, repositoryData) ->

@mhl-b
Copy link
Contributor Author

mhl-b commented May 17, 2024

@DaveCTurner thank you for suggestions. Updated PR except verify condition.

Copy link
Contributor

@DaveCTurner DaveCTurner left a comment

Choose a reason for hiding this comment

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

LGTM

@mhl-b mhl-b added the auto-merge Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) label May 17, 2024
@elasticsearchmachine elasticsearchmachine merged commit 38283c8 into elastic:main May 17, 2024
15 checks passed
@mhl-b mhl-b deleted the register-repo-refactor branch May 17, 2024 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-merge Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) :Distributed/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs >non-issue Team:Distributed Meta label for distributed team v8.15.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants