History Sync: Use single, distinct DB connection #681
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 PR is another attempt at fixing #577 by using a single, distinct DB connection for the history sync.
The only database tables with foreign key constraints are found in the history context. By default - and for good reasons - a DB internally consists of a cluster of several database connections. However, if a multi-master database server setup is used, it can - and will - happen that this DB contains sessions to different servers and related queries will be submitted in the wrong order, at least in the eye of some database servers.
To prevent this problem, an extra DB with only one connection is used for the history sync. First, this required some refactoring on icingadb.DB, allowing to clone, copy or re-create a DB.
I have tested this change on top of #679, as it happened sometimes that my local Galera cluster wasn't completely ready yet. Thus, this PR should also be considered for merging.
This PR competes with #665 at fixing #577, as both are trying to solve the same issue. Even though I am not completely satisfied with the solution proposed here, I would like to emphasize that no database-specific commands are used and also no cluster sync is require for all
INSERTS
, also on unrelated tables, as I wrote before.Please feel free to test it and review it!