@@ -76,6 +76,7 @@ public class DriverChannel {
7676 private final ProtocolVersion protocolVersion ;
7777 private final AtomicBoolean closing = new AtomicBoolean ();
7878 private final AtomicBoolean forceClosing = new AtomicBoolean ();
79+ private ProtocolFeatureStore featureStore ;
7980
8081 DriverChannel (
8182 EndPoint endPoint ,
@@ -146,18 +147,35 @@ public Map<String, List<String>> getOptions() {
146147 return channel .attr (OPTIONS_KEY ).get ();
147148 }
148149
150+ public ProtocolFeatureStore getSupportedFeatures () {
151+ if (featureStore != null ) {
152+ return featureStore ;
153+ }
154+
155+ ProtocolFeatureStore fromChannel = ProtocolFeatureStore .loadFromChannel (channel );
156+ if (fromChannel == null ) {
157+ return ProtocolFeatureStore .Empty ;
158+ }
159+ // Features can't be renegotiated.
160+ // Once features is populated into channel it is enough to update cache and no need to
161+ // invalidate it further.
162+
163+ featureStore = fromChannel ;
164+ return featureStore ;
165+ }
166+
149167 public int getShardId () {
150- ConnectionShardingInfo info = ProtocolFeatureStore . loadFromChannel ( channel ).getShardingInfo ();
168+ ConnectionShardingInfo info = getSupportedFeatures ( ).getShardingInfo ();
151169 return info != null ? info .shardId : 0 ;
152170 }
153171
154172 public ShardingInfo getShardingInfo () {
155- ConnectionShardingInfo info = ProtocolFeatureStore . loadFromChannel ( channel ).getShardingInfo ();
173+ ConnectionShardingInfo info = getSupportedFeatures ( ).getShardingInfo ();
156174 return info != null ? info .shardingInfo : null ;
157175 }
158176
159177 public LwtInfo getLwtInfo () {
160- return ProtocolFeatureStore . loadFromChannel ( channel ).getLwtFeatureInfo ();
178+ return getSupportedFeatures ( ).getLwtFeatureInfo ();
161179 }
162180
163181 /**
0 commit comments