Skip to content

Conversation

@original-brownbear
Copy link
Contributor

Addresses this comment #9488 (comment)

* Move `createRepository` call out of cluster state tasks
    * Now only `RepositoriesService#applyClusterState` manipulates `this.repositories`
* Closes elastic#9488
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-distributed

Repository newRepo = createRepository(repositoryMetaData);
createRepository(repositoryMetaData);
if (previous != null) {
closeRepository(previous);
Copy link
Contributor

Choose a reason for hiding this comment

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

that looks dangerous now (i.e., closing the existing repo). You should rather close the temporarily created repository.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, the existing one is closed in org.elasticsearch.repositories.RepositoriesService#applyClusterState anyway as far as I can see :)

*/
private boolean registerRepository(RepositoryMetaData repositoryMetaData) throws IOException {
private boolean registerRepository(RepositoryMetaData repositoryMetaData) {
Repository previous = repositories.get(repositoryMetaData.name());
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if this logic is still needed. If we want to keep the logic to check if there have been no changes, we should just take the current repository metadata from the cluster state, and do this on the cluster state update task.

Copy link
Contributor

Choose a reason for hiding this comment

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

you can then also inline this method so that it only becomes something like

try {
    closeRepository(createRepository(newRepositoryMetaData));
} catch (Exception e) {
    registrationListener.onFailure(e);
    return;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense :) Inlined as you suggest above and added a breakout to the cluster state task for the case of equal metadata.

@original-brownbear
Copy link
Contributor Author

@ywelsch thanks for taking a look! Applied your suggestions now :)

Copy link
Contributor

@ywelsch ywelsch left a comment

Choose a reason for hiding this comment

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

Can you add tests as well for the case where the repo with same settings exist? I'm not sure we have an existing test case for that (maybe look in RepositoriesIT)

@original-brownbear
Copy link
Contributor Author

@ywelsch sure, done in 546d0fc :)

@ywelsch ywelsch added >enhancement and removed >bug labels Dec 4, 2018
Copy link
Contributor

@ywelsch ywelsch left a comment

Choose a reason for hiding this comment

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

LGTM

@original-brownbear
Copy link
Contributor Author

@ywelsch thanks :)

@original-brownbear original-brownbear merged commit 3c54b41 into elastic:master Dec 4, 2018
@original-brownbear original-brownbear deleted the 9488 branch December 4, 2018 19:53
original-brownbear added a commit that referenced this pull request Dec 4, 2018
* Move `createRepository` call out of cluster state tasks
    * Now only `RepositoriesService#applyClusterState` manipulates `this.repositories`
* Closes #9488
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants