Skip to content

Commit f9239c6

Browse files
committed
Pull ShardingInfo into ProtocolFeatureStore
1 parent c815f46 commit f9239c6

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ public class DriverChannel {
6262
static final AttributeKey<String> CLUSTER_NAME_KEY = AttributeKey.valueOf("cluster_name");
6363
static final AttributeKey<Map<String, List<String>>> OPTIONS_KEY =
6464
AttributeKey.valueOf("options");
65-
static final AttributeKey<ConnectionShardingInfo> SHARDING_INFO_KEY =
66-
AttributeKey.valueOf("sharding_info");
6765

6866
@SuppressWarnings("RedundantStringConstructorCall")
6967
static final Object GRACEFUL_CLOSE_MESSAGE = new String("GRACEFUL_CLOSE_MESSAGE");
@@ -149,13 +147,13 @@ public Map<String, List<String>> getOptions() {
149147
}
150148

151149
public int getShardId() {
152-
return channel.hasAttr(SHARDING_INFO_KEY) ? channel.attr(SHARDING_INFO_KEY).get().shardId : 0;
150+
ConnectionShardingInfo info = ProtocolFeatureStore.loadFromChannel(channel).getShardingInfo();
151+
return info != null ? info.shardId : 0;
153152
}
154153

155154
public ShardingInfo getShardingInfo() {
156-
return channel.hasAttr(SHARDING_INFO_KEY)
157-
? channel.attr(SHARDING_INFO_KEY).get().shardingInfo
158-
: null;
155+
ConnectionShardingInfo info = ProtocolFeatureStore.loadFromChannel(channel).getShardingInfo();
156+
return info != null ? info.shardingInfo : null;
159157
}
160158

161159
public LwtInfo getLwtInfo() {

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@
4242
import com.datastax.oss.driver.internal.core.protocol.ProtocolFeatureStore;
4343
import com.datastax.oss.driver.internal.core.protocol.SegmentToBytesEncoder;
4444
import com.datastax.oss.driver.internal.core.protocol.SegmentToFrameDecoder;
45-
import com.datastax.oss.driver.internal.core.protocol.ShardingInfo;
46-
import com.datastax.oss.driver.internal.core.protocol.ShardingInfo.ConnectionShardingInfo;
4745
import com.datastax.oss.driver.internal.core.protocol.TabletInfo;
4846
import com.datastax.oss.driver.internal.core.util.ProtocolUtils;
4947
import com.datastax.oss.driver.internal.core.util.concurrent.UncaughtExceptions;
@@ -227,10 +225,6 @@ void onResponse(Message response) {
227225
channel.attr(DriverChannel.OPTIONS_KEY).set(((Supported) response).options);
228226
Supported res = (Supported) response;
229227
featureStore = ProtocolFeatureStore.parseSupportedOptions(res.options);
230-
ConnectionShardingInfo shardingInfo = ShardingInfo.parseShardingInfo(res.options);
231-
if (shardingInfo != null) {
232-
channel.attr(DriverChannel.SHARDING_INFO_KEY).set(shardingInfo);
233-
}
234228
tabletInfo = TabletInfo.parseTabletInfo(res.options);
235229
featureStore.storeInChannel(channel);
236230
step = Step.STARTUP;

core/src/main/java/com/datastax/oss/driver/internal/core/protocol/ProtocolFeatureStore.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,25 @@ public class ProtocolFeatureStore {
1111
AttributeKey.valueOf("protocol_feature_store");
1212

1313
private final LwtInfo lwtInfo;
14+
private final ShardingInfo.ConnectionShardingInfo shardingInfo;
1415

15-
ProtocolFeatureStore(LwtInfo lwtInfo) {
16+
ProtocolFeatureStore(LwtInfo lwtInfo, ShardingInfo.ConnectionShardingInfo shardingInfo) {
1617
this.lwtInfo = lwtInfo;
18+
this.shardingInfo = shardingInfo;
1719
}
1820

1921
public LwtInfo getLwtFeatureInfo() {
2022
return lwtInfo;
2123
}
2224

25+
public ShardingInfo.ConnectionShardingInfo getShardingInfo() {
26+
return shardingInfo;
27+
}
28+
2329
public static ProtocolFeatureStore parseSupportedOptions(Map<String, List<String>> options) {
2430
LwtInfo lwtInfo = LwtInfo.loadFromSupportedOptions(options);
25-
return new ProtocolFeatureStore(lwtInfo);
31+
ShardingInfo.ConnectionShardingInfo shardingInfo = ShardingInfo.parseShardingInfo(options);
32+
return new ProtocolFeatureStore(lwtInfo, shardingInfo);
2633
}
2734

2835
public void populateStartupOptions(Map<String, String> options) {

0 commit comments

Comments
 (0)