Skip to content

Commit 34e8f1f

Browse files
Alexandre Dutraolim7t
authored andcommitted
JAVA-1120: Skip schema refresh debouncer when checking for agreement as a result of schema change made by client
This commit contains substantial contributions by Andrew Tolbert (@tolbertam). This commit removes nonDebouncingQueryOptions from tests that no longer require it.
1 parent 4abf893 commit 34e8f1f

8 files changed

Lines changed: 21 additions & 12 deletions

File tree

changelog/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- [bug] JAVA-1160: Fix NPE in VersionNumber.getPreReleaseLabels().
2020
- [improvement] JAVA-1126: Handle schema changes in Mapper.
2121
- [bug] JAVA-1193: Refresh token and replica metadata synchronously when schema is altered.
22+
- [bug] JAVA-1120: Skip schema refresh debouncer when checking for agreement as a result of schema change made by client.
2223

2324

2425
### 3.0.2

driver-core/src/main/java/com/datastax/driver/core/Cluster.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2266,7 +2266,15 @@ public void run() {
22662266
if (!schemaInAgreement)
22672267
logger.warn("No schema agreement from live replicas after {} s. The schema may not be up to date on some nodes.", configuration.getProtocolOptions().getMaxSchemaAgreementWaitSeconds());
22682268

2269-
ListenableFuture<Void> schemaReady = refreshSchema ? submitSchemaRefresh(targetType, targetKeyspace, targetName, targetSignature) : MoreFutures.VOID_SUCCESS;
2269+
ListenableFuture<Void> schemaReady;
2270+
if (refreshSchema) {
2271+
schemaReady = submitSchemaRefresh(targetType, targetKeyspace, targetName, targetSignature);
2272+
// JAVA-1120: skip debouncing delay and force immediate delivery
2273+
if (!schemaReady.isDone())
2274+
schemaRefreshRequestDebouncer.scheduleImmediateDelivery();
2275+
} else {
2276+
schemaReady = MoreFutures.VOID_SUCCESS;
2277+
}
22702278
final boolean finalSchemaInAgreement = schemaInAgreement;
22712279
schemaReady.addListener(new Runnable() {
22722280
@Override

driver-core/src/main/java/com/datastax/driver/core/EventDebouncer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ ListenableFuture<Void> eventReceived(T event) {
164164
return entry.future;
165165
}
166166

167-
private void scheduleImmediateDelivery() {
167+
void scheduleImmediateDelivery() {
168168
cancelDelayedDelivery();
169169

170170
while (state == State.RUNNING) {

driver-core/src/test/java/com/datastax/driver/core/ClusterInitTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
import static com.datastax.driver.core.Assertions.fail;
4343
import static com.datastax.driver.core.FakeHost.Behavior.THROWING_CONNECT_TIMEOUTS;
4444
import static com.datastax.driver.core.HostDistance.LOCAL;
45-
import static com.datastax.driver.core.TestUtils.*;
45+
import static com.datastax.driver.core.TestUtils.ipOfNode;
46+
import static com.datastax.driver.core.TestUtils.nonQuietClusterCloseOptions;
4647
import static org.mockito.Mockito.*;
4748

4849
public class ClusterInitTest {
@@ -107,7 +108,6 @@ public void should_handle_failing_or_missing_contact_points() throws UnknownHost
107108
.withReconnectionPolicy(reconnectionPolicy)
108109
.withPoolingOptions(poolingOptions)
109110
.withProtocolVersion(TestUtils.getDesiredProtocolVersion())
110-
.withQueryOptions(nonDebouncingQueryOptions())
111111
.build();
112112
cluster.connect();
113113

@@ -228,7 +228,7 @@ public void should_not_abort_init_if_host_does_not_support_protocol_version() {
228228
ScassandraCluster scassandraCluster = ScassandraCluster.builder()
229229
.withIpPrefix(TestUtils.IP_PREFIX)
230230
.withNodes(5)
231-
// For node 2, report an older version which uses protocol v1.
231+
// For node 2, report an older version which uses protocol v1.
232232
.forcePeerInfo(1, 2, "release_version", "1.2.19")
233233
.build();
234234
Cluster cluster = Cluster.builder()
@@ -262,7 +262,7 @@ private void primePeerRows(Scassandra scassandra, List<FakeHost> otherHosts) thr
262262
PrimingClient.builder()
263263
.withHost(ipOfNode(1))
264264
.withPort(scassandra.getAdminPort())
265-
.build();
265+
.build();
266266

267267
List<Map<String, ?>> rows = Lists.newArrayListWithCapacity(5);
268268

driver-core/src/test/java/com/datastax/driver/core/HostMetadataIntegrationTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import static com.datastax.driver.core.Assertions.assertThat;
2525
import static com.datastax.driver.core.CCMAccess.Workload.solr;
2626
import static com.datastax.driver.core.CCMAccess.Workload.spark;
27-
import static com.datastax.driver.core.TestUtils.nonDebouncingQueryOptions;
2827
import static com.datastax.driver.core.TestUtils.nonQuietClusterCloseOptions;
2928

3029
public class HostMetadataIntegrationTest {
@@ -58,7 +57,6 @@ public void test_mixed_dse_workload() {
5857
Cluster cluster = Cluster.builder()
5958
.addContactPoints(ccm.addressOfNode(1).getAddress())
6059
.withPort(ccm.getBinaryPort())
61-
.withQueryOptions(nonDebouncingQueryOptions())
6260
.build();
6361
try {
6462
cluster.connect();

driver-core/src/test/java/com/datastax/driver/core/SchemaRefreshDebouncerTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import org.mockito.ArgumentCaptor;
1919
import org.testng.SkipException;
20-
import org.testng.annotations.AfterMethod;
2120
import org.testng.annotations.BeforeMethod;
2221
import org.testng.annotations.Test;
2322

@@ -249,6 +248,8 @@ public void should_debounce_and_coalesce_multiple_keyspace_creates_into_refresh_
249248
String prefix = TestUtils.generateIdentifier("ks_");
250249
for (int i = 0; i < 3; i++) {
251250
session().execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, prefix + i, 1));
251+
// check that the metadata is immediately up-to-date for the client that issued the DDL statement
252+
assertThat(cluster().getMetadata().getKeyspace(prefix + i)).isNotNull();
252253
}
253254

254255
verify(listener, timeout(DEBOUNCE_TIME * 3).times(3)).onKeyspaceAdded(any(KeyspaceMetadata.class));
@@ -275,6 +276,8 @@ public void should_refresh_when_max_pending_requests_reached() throws Exception
275276
String prefix = TestUtils.generateIdentifier("ks_");
276277
for (int i = 0; i < 5; i++) {
277278
session().execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, prefix + i, 1));
279+
// check that the metadata is immediately up-to-date for the client that issued the DDL statement
280+
assertThat(cluster().getMetadata().getKeyspace(prefix + i)).isNotNull();
278281
}
279282

280283
// Event should be processed immediately as we hit our threshold.

driver-core/src/test/java/com/datastax/driver/core/TokenIntegrationTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ public Cluster.Builder createClusterBuilder() {
6161
return Cluster.builder()
6262
.addContactPoints(getContactPoints().get(0))
6363
.withPort(ccm().getBinaryPort())
64-
.withLoadBalancingPolicy(lbp)
65-
.withQueryOptions(TestUtils.nonDebouncingQueryOptions());
64+
.withLoadBalancingPolicy(lbp);
6665
}
6766

6867
@Override

driver-mapping/src/test/java/com/datastax/driver/mapping/MapperAsyncTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void should_get_query_async_without_blocking() {
7171
// create a second cluster to perform everything asynchronously,
7272
// including session initialization
7373
Cluster cluster2 = register(
74-
createClusterBuilderNoDebouncing()
74+
createClusterBuilder()
7575
.addContactPoints(getContactPoints())
7676
.withPort(ccm().getBinaryPort())
7777
.build());

0 commit comments

Comments
 (0)