@@ -74,16 +74,44 @@ class Features
7474 SERVER_TOO_OLD = "Server at (%s) reports wire version (%s), but this version of the Ruby driver " +
7575 "requires at least (%s)."
7676
77+ # Warning message if the server version is deprecated.
78+ SERVER_DEPRECATED = 'Server at (%s) reports wire version (%s), but support for that wire version ' \
79+ 'is deprecated and will be removed in a future version of the Ruby driver. ' \
80+ 'Please upgrade your MongoDB server to a newer version soon.'
81+
7782 # Error message if the driver is too old for the version of the server.
7883 #
7984 # @since 2.5.0
8085 DRIVER_TOO_OLD = "Server at (%s) requires wire version (%s), but this version of the Ruby driver " +
8186 "only supports up to (%s)."
8287
88+ # An empty range constant, for use in DEPRECATED_WIRE_VERSIONS.
89+ EMPTY_RANGE = ( 0 ...0 ) . freeze
90+
8391 # The wire protocol versions that this version of the driver supports.
8492 #
8593 # @since 2.0.0
86- DRIVER_WIRE_VERSIONS = ( 6 ..25 ) . freeze
94+ DRIVER_WIRE_VERSIONS = 6 ..25
95+
96+ # The wire protocol versions that are deprecated in this version of the
97+ # driver. Support for these versions will be removed in the future.
98+ #
99+ # If there are multiple currently-deprecated wire versions, this should
100+ # be set to a range of those versions.
101+ #
102+ # If there is only a single currently-deprecated wire version, this should
103+ # be set to a range where the min and max are the same value.
104+ #
105+ # If there are no currently-deprecated wire versions, this should be
106+ # set to an empty range (e.g. the EMPTY_RANGE constant).
107+ DEPRECATED_WIRE_VERSIONS = 6 ..6
108+
109+ # make sure the deprecated versions are valid
110+ if DEPRECATED_WIRE_VERSIONS . min
111+ if DRIVER_WIRE_VERSIONS . min > DEPRECATED_WIRE_VERSIONS . max
112+ raise ArgumentError , 'DEPRECATED_WIRE_VERSIONS must be empty, or be within DRIVER_WIRE_VERSIONS'
113+ end
114+ end
87115
88116 # Create the methods for each mapping to tell if they are supported.
89117 #
@@ -131,20 +159,21 @@ def initialize(server_wire_versions, address = nil)
131159 end
132160
133161 # Check that there is an overlap between the driver supported wire
134- # version range and the server wire version range.
135- #
136- # @example Verify the wire version overlap.
137- # features.check_driver_support!
162+ # version range and the server wire version range. Also checks to see
163+ # if the server is using a deprecated wire version.
138164 #
139165 # @raise [ Error::UnsupportedFeatures ] If the wire version range is
140166 # not covered by the driver.
141- #
142- # @since 2.5.1
143167 def check_driver_support!
144- if DRIVER_WIRE_VERSIONS . min > @server_wire_versions . max
168+ if DEPRECATED_WIRE_VERSIONS . include? ( @server_wire_versions . max )
169+ feature = "wire_version:#{ @address } "
170+ Mongo ::Deprecations . warn ( feature , SERVER_DEPRECATED % [ @address , @server_wire_versions . max ] )
171+
172+ elsif DRIVER_WIRE_VERSIONS . min > @server_wire_versions . max
145173 raise Error ::UnsupportedFeatures . new ( SERVER_TOO_OLD % [ @address ,
146174 @server_wire_versions . max ,
147175 DRIVER_WIRE_VERSIONS . min ] )
176+
148177 elsif DRIVER_WIRE_VERSIONS . max < @server_wire_versions . min
149178 raise Error ::UnsupportedFeatures . new ( DRIVER_TOO_OLD % [ @address ,
150179 @server_wire_versions . min ,
0 commit comments