Skip to content

Commit 22254de

Browse files
committed
[#567] Initial implementation of SCYLLA_USE_METADATA_ID feature negotiation during driver startup 🚀
1 parent c800792 commit 22254de

File tree

2 files changed

+48
-5
lines changed

2 files changed

+48
-5
lines changed

core/src/main/java/com/datastax/oss/driver/internal/core/channel/ProtocolInitHandler.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import com.datastax.oss.driver.internal.core.protocol.BytesToSegmentDecoder;
4242
import com.datastax.oss.driver.internal.core.protocol.FrameToSegmentEncoder;
4343
import com.datastax.oss.driver.internal.core.protocol.LwtInfo;
44+
import com.datastax.oss.driver.internal.core.protocol.MetadataIdInfo;
4445
import com.datastax.oss.driver.internal.core.protocol.SegmentToBytesEncoder;
4546
import com.datastax.oss.driver.internal.core.protocol.SegmentToFrameDecoder;
4647
import com.datastax.oss.driver.internal.core.protocol.ShardingInfo;
@@ -98,6 +99,7 @@ class ProtocolInitHandler extends ConnectInitHandler {
9899
private final boolean querySupportedOptions;
99100
private LwtInfo lwtInfo;
100101
private TabletInfo tabletInfo;
102+
private MetadataIdInfo metadataIdInfo;
101103

102104
/**
103105
* @param querySupportedOptions whether to send OPTIONS as the first message, to request which
@@ -198,6 +200,9 @@ Message getRequest() {
198200
if (tabletInfo != null && tabletInfo.isEnabled()) {
199201
TabletInfo.addOption(startupOptions);
200202
}
203+
if (metadataIdInfo != null && metadataIdInfo.isEnabled()) {
204+
MetadataIdInfo.addOption(startupOptions);
205+
}
201206
return request = new Startup(startupOptions);
202207
case GET_CLUSTER_NAME:
203208
return request = CLUSTER_NAME_QUERY;
@@ -227,17 +232,20 @@ void onResponse(Message response) {
227232
ProtocolUtils.opcodeString(response.opcode));
228233
try {
229234
if (step == Step.OPTIONS && response instanceof Supported) {
230-
channel.attr(DriverChannel.OPTIONS_KEY).set(((Supported) response).options);
231-
Supported res = (Supported) response;
232-
ConnectionShardingInfo shardingInfo = ShardingInfo.parseShardingInfo(res.options);
235+
Supported supported = (Supported) response;
236+
channel.attr(DriverChannel.OPTIONS_KEY).set(supported.options);
237+
ConnectionShardingInfo shardingInfo = ShardingInfo.parseShardingInfo(supported.options);
233238
if (shardingInfo != null) {
234239
channel.attr(DriverChannel.SHARDING_INFO_KEY).set(shardingInfo);
235240
}
236-
lwtInfo = LwtInfo.parseLwtInfo(res.options);
241+
lwtInfo = LwtInfo.parseLwtInfo(supported.options);
237242
if (lwtInfo != null) {
238243
channel.attr(LWT_INFO_KEY).set(lwtInfo);
239244
}
240-
tabletInfo = TabletInfo.parseTabletInfo(res.options);
245+
tabletInfo = TabletInfo.parseTabletInfo(supported.options);
246+
metadataIdInfo =
247+
MetadataIdInfo.parseMetadataId(
248+
supported.options); // TODO: Check if setting channel attribute is needed
241249
step = Step.STARTUP;
242250
send();
243251
} else if (step == Step.STARTUP && response instanceof Ready) {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.datastax.oss.driver.internal.core.protocol;
2+
3+
import java.util.List;
4+
import java.util.Map;
5+
6+
public class MetadataIdInfo {
7+
private static final String SCYLLA_USE_METADATA_ID_STARTUP_OPTION_KEY = "SCYLLA_USE_METADATA_ID";
8+
private static final String SCYLLA_USE_METADATA_ID_STARTUP_OPTION_VALUE = "";
9+
10+
private final boolean enabled;
11+
12+
private MetadataIdInfo(boolean enabled) {
13+
this.enabled = enabled;
14+
}
15+
16+
public boolean isEnabled() {
17+
return enabled;
18+
}
19+
20+
public static MetadataIdInfo parseMetadataId(Map<String, List<String>> supported) {
21+
if (!supported.containsKey(SCYLLA_USE_METADATA_ID_STARTUP_OPTION_KEY)) {
22+
return new MetadataIdInfo(false);
23+
}
24+
List<String> values = supported.get(SCYLLA_USE_METADATA_ID_STARTUP_OPTION_KEY);
25+
return new MetadataIdInfo(
26+
values != null
27+
&& values.size() == 1
28+
&& values.get(0).equals(SCYLLA_USE_METADATA_ID_STARTUP_OPTION_VALUE));
29+
}
30+
31+
public static void addOption(Map<String, String> options) {
32+
options.put(
33+
SCYLLA_USE_METADATA_ID_STARTUP_OPTION_KEY, SCYLLA_USE_METADATA_ID_STARTUP_OPTION_VALUE);
34+
}
35+
}

0 commit comments

Comments
 (0)