[WIP] Improve repository registration #31070
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a work in progress pull request, I opened it to gather @ywelsch's opinion on it.
The current
RepositoriesService
has some issues, the most notable being that repository instances are created and started on the cluster state update thread (reported in #9488). Another one is that repository can fail to be created on non-master nodes and today the instance is just abruptly closed. Another one is that a repository is closed when it is unregistered but there is no control if the instance is used somewhere else.I think that the respository registration could be improved when it registers a repository. It could first check if the repository is used and fails directly in this case, without executing a cluster state update. Same thing if the repository metadata are unchanged, no need to trigger another cluster state update.
It could also create the repository and starts it first on the master node, and only adds it to the cluster state if everything is ok. If something goes wrong the newly created repository instance is just closed and an error is reported to the listener. This way the cluster state update is a light operation - it replaces the repository instance in a in memory map and puts the old repository (in case of an update) to a list of repository to be closed once the cluster state is applied. On non-master node, we can always create the repository instance and also keep around the previous repository instance to close it later. If the repository failed to be created, the error is logged and the in memory repository becomes a FailedRepository instance that throws UnsupportedException every time it is used. The repository must be deleted and recreated in this case.
In addition to this pull request (but not implemented here) I think that
Repository
could be aRefCounted
so everything that uses a Repository instance could useincRef()/decRef()
and we could close the repository is a cleaner way that is done today.