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

Change session/cluster initialization to happen in the background CSHARP-916 #528

Open
wants to merge 31 commits into
base: 4.x
Choose a base branch
from

Conversation

joao-r-reis
Copy link
Collaborator

@joao-r-reis joao-r-reis commented Jun 23, 2020

Currently cluster.Connect() starts the initialization task of the control connection, then creates the session, then initializes the session.

This PR changes this behavior so that cluster.Connect() creates the session object and returns it to the user immediately. The session initialization task is started in the background which will start the cluster initialization if it's not initialized yet.

If a user attempts to do something with the session, cluster or cluster.Metadata that requires the initialization to be finished, the method will await/block until the initialization task is complete.

I also implemented CSHARP-698 on this PR. It uses the reconnection policy to keep retrying the control connection initialization in the background. **After an initialization attempt fails, all method calls (session.Execute, etc.) will throw the original exception until a new attempt is started. When a new attempt is started, the methods will block again until the current attempt finishes.

This PR also adds Session.Connect() for users that want to wait for the initialization to be finished.

Several API changes are required in order for this to be a good experience for the user.

The Cluster.Metadata property no longer blocks. Also introduced a IMetadata interface and a IMetadataSnapshotProvider that declares some Metadata methods which do not block.

ILoadBalancingPolicy.Initialize is called by the initialization method but a ICluster instance is passed to that method which means that if the user attempts to access Metadata it will deadlock because it requires the initialization task to be finished. This PR changes this method so that it receives a IMetadataSnapshotProvider instance instead (which is inherited by IMetadata). It also changes the method to support async (returns Task).

A lot of methods from ICluster and ISession are moved to Metadata. This simplifies the driver's API because these methods and properties were just wrappers of those in Metadata so it makes more sense to be on the IMetadata interface only.

Also updated the upgrade guide so it's easier to get the overall picture of these API changes by reading the guide.

@joao-r-reis
Copy link
Collaborator Author

This PR doesn't unify Session and Cluster yet but a lot of these changes were made with the unification in mind which will come in a following PR.

I'm opening this PR before fixing the test code in order to allow for an earlier review of the API changes/design @jorgebay

@joao-r-reis joao-r-reis requested a review from jorgebay June 23, 2020 19:56
@joao-r-reis joao-r-reis added this to the 4.0.0 milestone Jun 24, 2020
@joao-r-reis joao-r-reis changed the base branch from master to 4.x June 24, 2020 09:44
* Remove IDisposable implementation
* Move ControlConnection construction to Metadata
* Add Metadata InitializeAsync and ShutdownAsync
- add IMetadata interface and change Metadata to be internal
- add *Async methods to IMetadata
- change internal references from Metadata to InternalMetadata
- add *Snapshot methods to IMetadata
@joao-r-reis joao-r-reis removed this from the 4.0.0 milestone Sep 10, 2020
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.

1 participant