Skip to content

Commit

Permalink
JAVA-2082: Avoid race condition during cluster close and schema refre…
Browse files Browse the repository at this point in the history
…sh (#1174)
  • Loading branch information
adutra authored Feb 21, 2019
1 parent 5c98360 commit 3cb45e8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- [documentation] JAVA-1964: Complete remaining "Coming Soon" sections in docs.
- [improvement] JAVA-1950: Log server side warnings returned from a query.
- [improvement] JAVA-2123: Allow to use QueryBuilder for building queries against Materialized Views.
- [bug] JAVA-2082: Avoid race condition during cluster close and schema refresh.


### 3.6.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ void stop() {
break;
}
}
while (true) {
DeliveryAttempt previous = cancelImmediateDelivery();
if (immediateDelivery.compareAndSet(previous, null)) {
break;
}
}

completeAllPendingFutures();

Expand Down Expand Up @@ -205,14 +211,21 @@ private void scheduleDelayedDelivery() {
}

private DeliveryAttempt cancelDelayedDelivery() {
DeliveryAttempt previous = delayedDelivery.get();
return cancelDelivery(delayedDelivery.get());
}

private DeliveryAttempt cancelImmediateDelivery() {
return cancelDelivery(immediateDelivery.get());
}

private DeliveryAttempt cancelDelivery(DeliveryAttempt previous) {
if (previous != null) {
previous.cancel();
}
return previous;
}

void deliverEvents() {
private void deliverEvents() {
if (state == State.STOPPED) {
completeAllPendingFutures();
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,13 @@ void refresh(
connection,
cassandraVersion);

Metadata metadata = cluster.getMetadata();
Metadata metadata;
try {
metadata = cluster.getMetadata();
} catch (IllegalStateException e) {
logger.warn("Unable to refresh metadata, cluster has been closed");
return;
}
metadata.lock.lock();
try {
if (targetType == null || targetType == KEYSPACE) {
Expand Down

0 comments on commit 3cb45e8

Please sign in to comment.