Skip to content

Commit f9b62e3

Browse files
committed
JAVA-2582 remove refreshFuture from SchemaQueriesFactory.newInstance()
1 parent e571163 commit f9b62e3

18 files changed

Lines changed: 32 additions & 98 deletions

changelog/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### 4.4.0 (in progress)
66

7+
- [improvement] JAVA-2582: Don't propagate a future into SchemaQueriesFactory
78
- [bug] JAVA-2556: Make ExecutionInfo compatible with any Request type
89
- [new feature] JAVA-2532: Add BoundStatement ReturnType for insert, update, and delete DAO methods
910
- [improvement] JAVA-2107: Add XML formatting plugin

core/src/main/java/com/datastax/oss/driver/internal/core/metadata/MetadataManager.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ private void startSchemaRequest(CompletableFuture<Metadata> future) {
408408
initControlConnectionForSchema()
409409
.thenCompose(v -> context.getTopologyMonitor().checkSchemaAgreement())
410410
// 1. Query system tables
411-
.thenCompose(b -> schemaQueriesFactory.newInstance(future).execute())
411+
.thenCompose(b -> schemaQueriesFactory.newInstance().execute())
412412
// 2. Parse the rows into metadata objects, put them in a MetadataRefresh
413413
// 3. Apply the MetadataRefresh
414414
.thenApplyAsync(this::parseAndApplySchemaRows, adminExecutor)
@@ -442,7 +442,6 @@ private CompletionStage<Void> initControlConnectionForSchema() {
442442

443443
private Void parseAndApplySchemaRows(SchemaRows schemaRows) {
444444
assert adminExecutor.inEventLoop();
445-
assert schemaRows.refreshFuture() == currentSchemaRefresh;
446445
try {
447446
SchemaRefresh schemaRefresh = schemaParserFactory.newInstance(schemaRows).parse();
448447
long start = System.nanoTime();

core/src/main/java/com/datastax/oss/driver/internal/core/metadata/schema/queries/Cassandra21SchemaQueries.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,15 @@
1616
package com.datastax.oss.driver.internal.core.metadata.schema.queries;
1717

1818
import com.datastax.oss.driver.api.core.config.DriverExecutionProfile;
19-
import com.datastax.oss.driver.api.core.metadata.Metadata;
2019
import com.datastax.oss.driver.internal.core.channel.DriverChannel;
2120
import java.util.Optional;
22-
import java.util.concurrent.CompletableFuture;
2321
import net.jcip.annotations.ThreadSafe;
2422

2523
@ThreadSafe
2624
public class Cassandra21SchemaQueries extends CassandraSchemaQueries {
2725
public Cassandra21SchemaQueries(
28-
DriverChannel channel,
29-
CompletableFuture<Metadata> refreshFuture,
30-
DriverExecutionProfile config,
31-
String logPrefix) {
32-
super(channel, false, refreshFuture, config, logPrefix);
26+
DriverChannel channel, DriverExecutionProfile config, String logPrefix) {
27+
super(channel, false, config, logPrefix);
3328
}
3429

3530
@Override

core/src/main/java/com/datastax/oss/driver/internal/core/metadata/schema/queries/Cassandra22SchemaQueries.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,15 @@
1616
package com.datastax.oss.driver.internal.core.metadata.schema.queries;
1717

1818
import com.datastax.oss.driver.api.core.config.DriverExecutionProfile;
19-
import com.datastax.oss.driver.api.core.metadata.Metadata;
2019
import com.datastax.oss.driver.internal.core.channel.DriverChannel;
2120
import java.util.Optional;
22-
import java.util.concurrent.CompletableFuture;
2321
import net.jcip.annotations.ThreadSafe;
2422

2523
@ThreadSafe
2624
public class Cassandra22SchemaQueries extends CassandraSchemaQueries {
2725
public Cassandra22SchemaQueries(
28-
DriverChannel channel,
29-
CompletableFuture<Metadata> refreshFuture,
30-
DriverExecutionProfile config,
31-
String logPrefix) {
32-
super(channel, false, refreshFuture, config, logPrefix);
26+
DriverChannel channel, DriverExecutionProfile config, String logPrefix) {
27+
super(channel, false, config, logPrefix);
3328
}
3429

3530
@Override

core/src/main/java/com/datastax/oss/driver/internal/core/metadata/schema/queries/Cassandra3SchemaQueries.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,15 @@
1616
package com.datastax.oss.driver.internal.core.metadata.schema.queries;
1717

1818
import com.datastax.oss.driver.api.core.config.DriverExecutionProfile;
19-
import com.datastax.oss.driver.api.core.metadata.Metadata;
2019
import com.datastax.oss.driver.internal.core.channel.DriverChannel;
2120
import java.util.Optional;
22-
import java.util.concurrent.CompletableFuture;
2321
import net.jcip.annotations.ThreadSafe;
2422

2523
@ThreadSafe
2624
public class Cassandra3SchemaQueries extends CassandraSchemaQueries {
2725
public Cassandra3SchemaQueries(
28-
DriverChannel channel,
29-
CompletableFuture<Metadata> refreshFuture,
30-
DriverExecutionProfile config,
31-
String logPrefix) {
32-
super(channel, true, refreshFuture, config, logPrefix);
26+
DriverChannel channel, DriverExecutionProfile config, String logPrefix) {
27+
super(channel, true, config, logPrefix);
3328
}
3429

3530
@Override

core/src/main/java/com/datastax/oss/driver/internal/core/metadata/schema/queries/Cassandra4SchemaQueries.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,15 @@
1616
package com.datastax.oss.driver.internal.core.metadata.schema.queries;
1717

1818
import com.datastax.oss.driver.api.core.config.DriverExecutionProfile;
19-
import com.datastax.oss.driver.api.core.metadata.Metadata;
2019
import com.datastax.oss.driver.internal.core.channel.DriverChannel;
2120
import java.util.Optional;
22-
import java.util.concurrent.CompletableFuture;
2321
import net.jcip.annotations.ThreadSafe;
2422

2523
@ThreadSafe
2624
public class Cassandra4SchemaQueries extends Cassandra3SchemaQueries {
2725
public Cassandra4SchemaQueries(
28-
DriverChannel channel,
29-
CompletableFuture<Metadata> refreshFuture,
30-
DriverExecutionProfile config,
31-
String logPrefix) {
32-
super(channel, refreshFuture, config, logPrefix);
26+
DriverChannel channel, DriverExecutionProfile config, String logPrefix) {
27+
super(channel, config, logPrefix);
3328
}
3429

3530
@Override

core/src/main/java/com/datastax/oss/driver/internal/core/metadata/schema/queries/CassandraSchemaQueries.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import com.datastax.oss.driver.api.core.config.DefaultDriverOption;
1919
import com.datastax.oss.driver.api.core.config.DriverExecutionProfile;
20-
import com.datastax.oss.driver.api.core.metadata.Metadata;
2120
import com.datastax.oss.driver.internal.core.adminrequest.AdminRequestHandler;
2221
import com.datastax.oss.driver.internal.core.adminrequest.AdminResult;
2322
import com.datastax.oss.driver.internal.core.adminrequest.AdminRow;
@@ -51,9 +50,6 @@ public abstract class CassandraSchemaQueries implements SchemaQueries {
5150
private final String whereClause;
5251
// The future we return from execute, completes when all the queries are done.
5352
private final CompletableFuture<SchemaRows> schemaRowsFuture = new CompletableFuture<>();
54-
// A future that completes later, when the whole refresh is done. We just store it here to pass it
55-
// down to the next step.
56-
public final CompletableFuture<Metadata> refreshFuture;
5753
private final long startTimeNs = System.nanoTime();
5854

5955
// All non-final fields are accessed exclusively on adminExecutor
@@ -63,13 +59,11 @@ public abstract class CassandraSchemaQueries implements SchemaQueries {
6359
protected CassandraSchemaQueries(
6460
DriverChannel channel,
6561
boolean isCassandraV3,
66-
CompletableFuture<Metadata> refreshFuture,
6762
DriverExecutionProfile config,
6863
String logPrefix) {
6964
this.channel = channel;
7065
this.adminExecutor = channel.eventLoop();
7166
this.isCassandraV3 = isCassandraV3;
72-
this.refreshFuture = refreshFuture;
7367
this.logPrefix = logPrefix;
7468
this.timeout = config.getDuration(DefaultDriverOption.METADATA_SCHEMA_REQUEST_TIMEOUT);
7569
this.pageSize = config.getInt(DefaultDriverOption.METADATA_SCHEMA_REQUEST_PAGE_SIZE);
@@ -129,7 +123,7 @@ public CompletionStage<SchemaRows> execute() {
129123
private void executeOnAdminExecutor() {
130124
assert adminExecutor.inEventLoop();
131125

132-
schemaRowsBuilder = new CassandraSchemaRows.Builder(isCassandraV3, refreshFuture, logPrefix);
126+
schemaRowsBuilder = new CassandraSchemaRows.Builder(isCassandraV3, logPrefix);
133127

134128
query(selectKeyspacesQuery() + whereClause, schemaRowsBuilder::withKeyspaces);
135129
query(selectTypesQuery() + whereClause, schemaRowsBuilder::withTypes);

core/src/main/java/com/datastax/oss/driver/internal/core/metadata/schema/queries/CassandraSchemaRows.java

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package com.datastax.oss.driver.internal.core.metadata.schema.queries;
1717

1818
import com.datastax.oss.driver.api.core.CqlIdentifier;
19-
import com.datastax.oss.driver.api.core.metadata.Metadata;
2019
import com.datastax.oss.driver.internal.core.adminrequest.AdminRow;
2120
import com.datastax.oss.driver.internal.core.metadata.schema.parsing.DataTypeClassNameParser;
2221
import com.datastax.oss.driver.internal.core.metadata.schema.parsing.DataTypeCqlNameParser;
@@ -29,7 +28,6 @@
2928
import java.util.LinkedHashMap;
3029
import java.util.List;
3130
import java.util.Map;
32-
import java.util.concurrent.CompletableFuture;
3331
import net.jcip.annotations.Immutable;
3432
import org.slf4j.Logger;
3533
import org.slf4j.LoggerFactory;
@@ -38,7 +36,6 @@
3836
public class CassandraSchemaRows implements SchemaRows {
3937

4038
private final DataTypeParser dataTypeParser;
41-
private final CompletableFuture<Metadata> refreshFuture;
4239
private final List<AdminRow> keyspaces;
4340
private final List<AdminRow> virtualKeyspaces;
4441
private final Multimap<CqlIdentifier, AdminRow> tables;
@@ -53,7 +50,6 @@ public class CassandraSchemaRows implements SchemaRows {
5350

5451
private CassandraSchemaRows(
5552
boolean isCassandraV3,
56-
CompletableFuture<Metadata> refreshFuture,
5753
List<AdminRow> keyspaces,
5854
List<AdminRow> virtualKeyspaces,
5955
Multimap<CqlIdentifier, AdminRow> tables,
@@ -67,7 +63,6 @@ private CassandraSchemaRows(
6763
Multimap<CqlIdentifier, AdminRow> aggregates) {
6864
this.dataTypeParser =
6965
isCassandraV3 ? new DataTypeCqlNameParser() : new DataTypeClassNameParser();
70-
this.refreshFuture = refreshFuture;
7166
this.keyspaces = keyspaces;
7267
this.virtualKeyspaces = virtualKeyspaces;
7368
this.tables = tables;
@@ -86,11 +81,6 @@ public DataTypeParser dataTypeParser() {
8681
return dataTypeParser;
8782
}
8883

89-
@Override
90-
public CompletableFuture<Metadata> refreshFuture() {
91-
return refreshFuture;
92-
}
93-
9484
@Override
9585
public List<AdminRow> keyspaces() {
9686
return keyspaces;
@@ -150,7 +140,6 @@ public static class Builder {
150140
private static final Logger LOG = LoggerFactory.getLogger(Builder.class);
151141

152142
private final boolean isCassandraV3;
153-
private final CompletableFuture<Metadata> refreshFuture;
154143
private final String tableNameColumn;
155144
private final String logPrefix;
156145
private final ImmutableList.Builder<AdminRow> keyspacesBuilder = ImmutableList.builder();
@@ -174,10 +163,8 @@ public static class Builder {
174163
private final Map<CqlIdentifier, ImmutableMultimap.Builder<CqlIdentifier, AdminRow>>
175164
indexesBuilders = new LinkedHashMap<>();
176165

177-
public Builder(
178-
boolean isCassandraV3, CompletableFuture<Metadata> refreshFuture, String logPrefix) {
166+
public Builder(boolean isCassandraV3, String logPrefix) {
179167
this.isCassandraV3 = isCassandraV3;
180-
this.refreshFuture = refreshFuture;
181168
this.logPrefix = logPrefix;
182169
this.tableNameColumn = isCassandraV3 ? "table_name" : "columnfamily_name";
183170
}
@@ -285,7 +272,6 @@ private void putByKeyspaceAndTable(
285272
public CassandraSchemaRows build() {
286273
return new CassandraSchemaRows(
287274
isCassandraV3,
288-
refreshFuture,
289275
keyspacesBuilder.build(),
290276
virtualKeyspacesBuilder.build(),
291277
tablesBuilder.build(),

core/src/main/java/com/datastax/oss/driver/internal/core/metadata/schema/queries/DefaultSchemaQueriesFactory.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@
1717

1818
import com.datastax.oss.driver.api.core.Version;
1919
import com.datastax.oss.driver.api.core.config.DriverExecutionProfile;
20-
import com.datastax.oss.driver.api.core.metadata.Metadata;
2120
import com.datastax.oss.driver.api.core.metadata.Node;
2221
import com.datastax.oss.driver.internal.core.channel.DriverChannel;
2322
import com.datastax.oss.driver.internal.core.context.InternalDriverContext;
2423
import com.datastax.oss.driver.internal.core.metadata.NodeProperties;
25-
import java.util.concurrent.CompletableFuture;
2624
import net.jcip.annotations.ThreadSafe;
2725
import org.slf4j.Logger;
2826
import org.slf4j.LoggerFactory;
@@ -41,7 +39,7 @@ public DefaultSchemaQueriesFactory(InternalDriverContext context) {
4139
}
4240

4341
@Override
44-
public SchemaQueries newInstance(CompletableFuture<Metadata> refreshFuture) {
42+
public SchemaQueries newInstance() {
4543
DriverChannel channel = context.getControlConnection().channel();
4644
if (channel == null || channel.closeFuture().isDone()) {
4745
throw new IllegalStateException("Control channel not available, aborting schema refresh");
@@ -57,11 +55,10 @@ public SchemaQueries newInstance(CompletableFuture<Metadata> refreshFuture) {
5755
"Could not find control node metadata "
5856
+ channel.getEndPoint()
5957
+ ", aborting schema refresh"));
60-
return newInstance(node, channel, refreshFuture);
58+
return newInstance(node, channel);
6159
}
6260

63-
protected SchemaQueries newInstance(
64-
Node node, DriverChannel channel, CompletableFuture<Metadata> refreshFuture) {
61+
protected SchemaQueries newInstance(Node node, DriverChannel channel) {
6562
Version version = node.getCassandraVersion();
6663
if (version == null) {
6764
LOG.warn(
@@ -76,11 +73,11 @@ protected SchemaQueries newInstance(
7673
DriverExecutionProfile config = context.getConfig().getDefaultProfile();
7774
LOG.debug("[{}] Sending schema queries to {} with version {}", logPrefix, node, version);
7875
if (version.compareTo(Version.V2_2_0) < 0) {
79-
return new Cassandra21SchemaQueries(channel, refreshFuture, config, logPrefix);
76+
return new Cassandra21SchemaQueries(channel, config, logPrefix);
8077
} else if (version.compareTo(Version.V3_0_0) < 0) {
81-
return new Cassandra22SchemaQueries(channel, refreshFuture, config, logPrefix);
78+
return new Cassandra22SchemaQueries(channel, config, logPrefix);
8279
} else if (version.compareTo(Version.V4_0_0) < 0) {
83-
return new Cassandra3SchemaQueries(channel, refreshFuture, config, logPrefix);
80+
return new Cassandra3SchemaQueries(channel, config, logPrefix);
8481
} else {
8582

8683
// A bit of custom logic for DSE 6.0.x. These versions report a Cassandra version of 4.0.0
@@ -92,10 +89,10 @@ protected SchemaQueries newInstance(
9289
assert (dseVersionObj instanceof Version);
9390
if (((Version) dseVersionObj).compareTo(Version.V6_7_0) < 0) {
9491

95-
return new Cassandra3SchemaQueries(channel, refreshFuture, config, logPrefix);
92+
return new Cassandra3SchemaQueries(channel, config, logPrefix);
9693
}
9794
}
98-
return new Cassandra4SchemaQueries(channel, refreshFuture, config, logPrefix);
95+
return new Cassandra4SchemaQueries(channel, config, logPrefix);
9996
}
10097
}
10198
}

core/src/main/java/com/datastax/oss/driver/internal/core/metadata/schema/queries/SchemaQueriesFactory.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
*/
1616
package com.datastax.oss.driver.internal.core.metadata.schema.queries;
1717

18-
import com.datastax.oss.driver.api.core.metadata.Metadata;
19-
import java.util.concurrent.CompletableFuture;
20-
2118
public interface SchemaQueriesFactory {
22-
SchemaQueries newInstance(CompletableFuture<Metadata> refreshFuture);
19+
SchemaQueries newInstance();
2320
}

0 commit comments

Comments
 (0)