Skip to content

Fix stale broken cluster connection in CassandraIO (#39788) - #39803

Open
sharan-malyala wants to merge 1 commit into
apache:release-2.76from
sharan-malyala:cherry-pick-39788
Open

Fix stale broken cluster connection in CassandraIO (#39788)#39803
sharan-malyala wants to merge 1 commit into
apache:release-2.76from
sharan-malyala:cherry-pick-39788

Conversation

@sharan-malyala

Copy link
Copy Markdown
Contributor

This PR fixes an issue in CassandraIO where read operations can fail if the underlying Cassandra Cluster connection is broken due to a transient issue avoiding subsequent work failures.

Previously, ConnectionManager would cache the Cluster and Session and continue to return them even if the cluster was in a broken state, leading to subsequent operation failures.

This change adds a validation step in ConnectionManager.getSession(). If the cached Cluster is found to be closed, the stale references are proactively removed from sessionMap and clusterMap. This ensures that a new, healthy Cluster and Session are transparently recreated via computeIfAbsent.

* Fix for CassandraIO read  connection issue

* Fixed a presubmit failure

* Added test case
@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @ahmedabu98 for label java.

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

@stankiewicz

Copy link
Copy Markdown
Contributor

R: @Amar3tto

@github-actions

Copy link
Copy Markdown
Contributor

Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment assign set of reviewers


Cluster cachedCluster = clusterMap.get(clusterHash);

if (cachedCluster != null && cachedCluster.isClosed()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Inside this if clause it modified sessionMap and clusterMap. Even though they are concurrent hash map, is there a risk of racing?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If we dont cleanup the session and just re-create cluster object, the broken session will be returned and used by the work items leading to failure.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I was thinking about the following scenario:

  1. A session corrupted and cluster closed

  2. Caller A runs getSession(), found cachedCluster.isClosed

  3. Caller B also runs getSession(), found cachedCluster.isClosed

  4. Caller A cleaned up session and cluster cache, recreated cluster connection

  5. Caller B clean up session again, because it's already inside the if clause. But it should not do so as the cache is current valid, may cause session leak.

Basically it seems the whole getSession now needs to be synchronized.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see, this is already merged in #39788 however a race appears possible

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I will check further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants