22
22
import org .elasticsearch .cluster .metadata .IndexMetaData ;
23
23
import org .elasticsearch .common .Strings ;
24
24
import org .elasticsearch .common .SuppressForbidden ;
25
+ import org .elasticsearch .common .collect .ImmutableOpenIntMap ;
25
26
import org .elasticsearch .common .io .stream .StreamInput ;
26
27
import org .elasticsearch .common .io .stream .StreamOutput ;
27
28
import org .elasticsearch .common .settings .Settings ;
@@ -46,205 +47,116 @@ public class Version implements Comparable<Version>, ToXContentFragment {
46
47
*/
47
48
public static final int V_EMPTY_ID = 0 ;
48
49
public static final Version V_EMPTY = new Version (V_EMPTY_ID , org .apache .lucene .util .Version .LATEST );
49
- public static final int V_6_0_0_alpha1_ID = 6000001 ;
50
+
50
51
public static final Version V_6_0_0_alpha1 =
51
- new Version (V_6_0_0_alpha1_ID , org .apache .lucene .util .Version .LUCENE_7_0_0 );
52
- public static final int V_6_0_0_alpha2_ID = 6000002 ;
52
+ new Version (6000001 , org .apache .lucene .util .Version .LUCENE_7_0_0 );
53
53
public static final Version V_6_0_0_alpha2 =
54
- new Version (V_6_0_0_alpha2_ID , org .apache .lucene .util .Version .LUCENE_7_0_0 );
55
- public static final int V_6_0_0_beta1_ID = 6000026 ;
54
+ new Version (6000002 , org .apache .lucene .util .Version .LUCENE_7_0_0 );
56
55
public static final Version V_6_0_0_beta1 =
57
- new Version (V_6_0_0_beta1_ID , org .apache .lucene .util .Version .LUCENE_7_0_0 );
58
- public static final int V_6_0_0_beta2_ID = 6000027 ;
56
+ new Version (6000026 , org .apache .lucene .util .Version .LUCENE_7_0_0 );
59
57
public static final Version V_6_0_0_beta2 =
60
- new Version (V_6_0_0_beta2_ID , org .apache .lucene .util .Version .LUCENE_7_0_0 );
61
- public static final int V_6_0_0_rc1_ID = 6000051 ;
58
+ new Version (6000027 , org .apache .lucene .util .Version .LUCENE_7_0_0 );
62
59
public static final Version V_6_0_0_rc1 =
63
- new Version (V_6_0_0_rc1_ID , org .apache .lucene .util .Version .LUCENE_7_0_0 );
64
- public static final int V_6_0_0_rc2_ID = 6000052 ;
60
+ new Version (6000051 , org .apache .lucene .util .Version .LUCENE_7_0_0 );
65
61
public static final Version V_6_0_0_rc2 =
66
- new Version (V_6_0_0_rc2_ID , org .apache .lucene .util .Version .LUCENE_7_0_1 );
67
- public static final int V_6_0_0_ID = 6000099 ;
62
+ new Version (6000052 , org .apache .lucene .util .Version .LUCENE_7_0_1 );
68
63
public static final Version V_6_0_0 =
69
- new Version (V_6_0_0_ID , org .apache .lucene .util .Version .LUCENE_7_0_1 );
70
- public static final int V_6_0_1_ID = 6000199 ;
64
+ new Version (6000099 , org .apache .lucene .util .Version .LUCENE_7_0_1 );
71
65
public static final Version V_6_0_1 =
72
- new Version (V_6_0_1_ID , org .apache .lucene .util .Version .LUCENE_7_0_1 );
73
- public static final int V_6_1_0_ID = 6010099 ;
74
- public static final Version V_6_1_0 = new Version (V_6_1_0_ID , org .apache .lucene .util .Version .LUCENE_7_1_0 );
75
- public static final int V_6_1_1_ID = 6010199 ;
76
- public static final Version V_6_1_1 = new Version (V_6_1_1_ID , org .apache .lucene .util .Version .LUCENE_7_1_0 );
77
- public static final int V_6_1_2_ID = 6010299 ;
78
- public static final Version V_6_1_2 = new Version (V_6_1_2_ID , org .apache .lucene .util .Version .LUCENE_7_1_0 );
79
- public static final int V_6_1_3_ID = 6010399 ;
80
- public static final Version V_6_1_3 = new Version (V_6_1_3_ID , org .apache .lucene .util .Version .LUCENE_7_1_0 );
81
- public static final int V_6_1_4_ID = 6010499 ;
82
- public static final Version V_6_1_4 = new Version (V_6_1_4_ID , org .apache .lucene .util .Version .LUCENE_7_1_0 );
66
+ new Version (6000199 , org .apache .lucene .util .Version .LUCENE_7_0_1 );
67
+ public static final Version V_6_1_0 = new Version (6010099 , org .apache .lucene .util .Version .LUCENE_7_1_0 );
68
+ public static final Version V_6_1_1 = new Version (6010199 , org .apache .lucene .util .Version .LUCENE_7_1_0 );
69
+ public static final Version V_6_1_2 = new Version (6010299 , org .apache .lucene .util .Version .LUCENE_7_1_0 );
70
+ public static final Version V_6_1_3 = new Version (6010399 , org .apache .lucene .util .Version .LUCENE_7_1_0 );
71
+ public static final Version V_6_1_4 = new Version (6010499 , org .apache .lucene .util .Version .LUCENE_7_1_0 );
83
72
// The below version is missing from the 7.3 JAR
84
73
private static final org .apache .lucene .util .Version LUCENE_7_2_1 = org .apache .lucene .util .Version .fromBits (7 , 2 , 1 );
85
- public static final int V_6_2_0_ID = 6020099 ;
86
- public static final Version V_6_2_0 = new Version (V_6_2_0_ID , LUCENE_7_2_1 );
87
- public static final int V_6_2_1_ID = 6020199 ;
88
- public static final Version V_6_2_1 = new Version (V_6_2_1_ID , LUCENE_7_2_1 );
89
- public static final int V_6_2_2_ID = 6020299 ;
90
- public static final Version V_6_2_2 = new Version (V_6_2_2_ID , LUCENE_7_2_1 );
91
- public static final int V_6_2_3_ID = 6020399 ;
92
- public static final Version V_6_2_3 = new Version (V_6_2_3_ID , LUCENE_7_2_1 );
93
- public static final int V_6_2_4_ID = 6020499 ;
94
- public static final Version V_6_2_4 = new Version (V_6_2_4_ID , LUCENE_7_2_1 );
95
- public static final int V_6_3_0_ID = 6030099 ;
96
- public static final Version V_6_3_0 = new Version (V_6_3_0_ID , org .apache .lucene .util .Version .LUCENE_7_3_1 );
97
- public static final int V_6_3_1_ID = 6030199 ;
98
- public static final Version V_6_3_1 = new Version (V_6_3_1_ID , org .apache .lucene .util .Version .LUCENE_7_3_1 );
99
- public static final int V_6_3_2_ID = 6030299 ;
100
- public static final Version V_6_3_2 = new Version (V_6_3_2_ID , org .apache .lucene .util .Version .LUCENE_7_3_1 );
101
- public static final int V_6_4_0_ID = 6040099 ;
102
- public static final Version V_6_4_0 = new Version (V_6_4_0_ID , org .apache .lucene .util .Version .LUCENE_7_4_0 );
103
- public static final int V_6_4_1_ID = 6040199 ;
104
- public static final Version V_6_4_1 = new Version (V_6_4_1_ID , org .apache .lucene .util .Version .LUCENE_7_4_0 );
105
- public static final int V_6_4_2_ID = 6040299 ;
106
- public static final Version V_6_4_2 = new Version (V_6_4_2_ID , org .apache .lucene .util .Version .LUCENE_7_4_0 );
107
- public static final int V_6_4_3_ID = 6040399 ;
108
- public static final Version V_6_4_3 = new Version (V_6_4_3_ID , org .apache .lucene .util .Version .LUCENE_7_4_0 );
109
- public static final int V_6_5_0_ID = 6050099 ;
110
- public static final Version V_6_5_0 = new Version (V_6_5_0_ID , org .apache .lucene .util .Version .LUCENE_7_5_0 );
111
- public static final int V_6_5_1_ID = 6050199 ;
112
- public static final Version V_6_5_1 = new Version (V_6_5_1_ID , org .apache .lucene .util .Version .LUCENE_7_5_0 );
113
- public static final int V_6_5_2_ID = 6050299 ;
114
- public static final Version V_6_5_2 = new Version (V_6_5_2_ID , org .apache .lucene .util .Version .LUCENE_7_5_0 );
115
- public static final int V_6_5_3_ID = 6050399 ;
116
- public static final Version V_6_5_3 = new Version (V_6_5_3_ID , org .apache .lucene .util .Version .LUCENE_7_5_0 );
117
- public static final int V_6_5_4_ID = 6050499 ;
118
- public static final Version V_6_5_4 = new Version (V_6_5_4_ID , org .apache .lucene .util .Version .LUCENE_7_5_0 );
119
- public static final int V_6_6_0_ID = 6060099 ;
120
- public static final Version V_6_6_0 = new Version (V_6_6_0_ID , org .apache .lucene .util .Version .LUCENE_7_6_0 );
121
- public static final int V_6_6_1_ID = 6060199 ;
122
- public static final Version V_6_6_1 = new Version (V_6_6_1_ID , org .apache .lucene .util .Version .LUCENE_7_6_0 );
123
- public static final int V_6_6_2_ID = 6060299 ;
124
- public static final Version V_6_6_2 = new Version (V_6_6_2_ID , org .apache .lucene .util .Version .LUCENE_7_6_0 );
125
- public static final int V_6_7_0_ID = 6070099 ;
126
- public static final Version V_6_7_0 = new Version (V_6_7_0_ID , org .apache .lucene .util .Version .LUCENE_7_7_0 );
127
- public static final int V_6_7_1_ID = 6070199 ;
128
- public static final Version V_6_7_1 = new Version (V_6_7_1_ID , org .apache .lucene .util .Version .LUCENE_7_7_0 );
129
- public static final int V_6_7_2_ID = 6070299 ;
130
- public static final Version V_6_7_2 = new Version (V_6_7_2_ID , org .apache .lucene .util .Version .LUCENE_7_7_0 );
131
- public static final int V_6_8_0_ID = 6080099 ;
132
- public static final Version V_6_8_0 = new Version (V_6_8_0_ID , org .apache .lucene .util .Version .LUCENE_7_7_0 );
133
- public static final int V_6_8_1_ID = 6080199 ;
134
- public static final Version V_6_8_1 = new Version (V_6_8_1_ID , org .apache .lucene .util .Version .LUCENE_7_7_0 );
135
- public static final int V_7_0_0_ID = 7000099 ;
136
- public static final Version V_7_0_0 = new Version (V_7_0_0_ID , org .apache .lucene .util .Version .LUCENE_8_0_0 );
137
- public static final int V_7_0_1_ID = 7000199 ;
138
- public static final Version V_7_0_1 = new Version (V_7_0_1_ID , org .apache .lucene .util .Version .LUCENE_8_0_0 );
139
- public static final int V_7_1_0_ID = 7010099 ;
140
- public static final Version V_7_1_0 = new Version (V_7_1_0_ID , org .apache .lucene .util .Version .LUCENE_8_0_0 );
141
- public static final int V_7_1_1_ID = 7010199 ;
142
- public static final Version V_7_1_1 = new Version (V_7_1_1_ID , org .apache .lucene .util .Version .LUCENE_8_0_0 );
143
- public static final int V_7_1_2_ID = 7010299 ;
144
- public static final Version V_7_1_2 = new Version (V_7_1_2_ID , org .apache .lucene .util .Version .LUCENE_8_0_0 );
145
- public static final int V_7_2_0_ID = 7020099 ;
146
- public static final Version V_7_2_0 = new Version (V_7_2_0_ID , org .apache .lucene .util .Version .LUCENE_8_0_0 );
74
+ public static final Version V_6_2_0 = new Version (6020099 , LUCENE_7_2_1 );
75
+ public static final Version V_6_2_1 = new Version (6020199 , LUCENE_7_2_1 );
76
+ public static final Version V_6_2_2 = new Version (6020299 , LUCENE_7_2_1 );
77
+ public static final Version V_6_2_3 = new Version (6020399 , LUCENE_7_2_1 );
78
+ public static final Version V_6_2_4 = new Version (6020499 , LUCENE_7_2_1 );
79
+ public static final Version V_6_3_0 = new Version (6030099 , org .apache .lucene .util .Version .LUCENE_7_3_1 );
80
+ public static final Version V_6_3_1 = new Version (6030199 , org .apache .lucene .util .Version .LUCENE_7_3_1 );
81
+ public static final Version V_6_3_2 = new Version (6030299 , org .apache .lucene .util .Version .LUCENE_7_3_1 );
82
+ public static final Version V_6_4_0 = new Version (6040099 , org .apache .lucene .util .Version .LUCENE_7_4_0 );
83
+ public static final Version V_6_4_1 = new Version (6040199 , org .apache .lucene .util .Version .LUCENE_7_4_0 );
84
+ public static final Version V_6_4_2 = new Version (6040299 , org .apache .lucene .util .Version .LUCENE_7_4_0 );
85
+ public static final Version V_6_4_3 = new Version (6040399 , org .apache .lucene .util .Version .LUCENE_7_4_0 );
86
+ public static final Version V_6_5_0 = new Version (6050099 , org .apache .lucene .util .Version .LUCENE_7_5_0 );
87
+ public static final Version V_6_5_1 = new Version (6050199 , org .apache .lucene .util .Version .LUCENE_7_5_0 );
88
+ public static final Version V_6_5_2 = new Version (6050299 , org .apache .lucene .util .Version .LUCENE_7_5_0 );
89
+ public static final Version V_6_5_3 = new Version (6050399 , org .apache .lucene .util .Version .LUCENE_7_5_0 );
90
+ public static final Version V_6_5_4 = new Version (6050499 , org .apache .lucene .util .Version .LUCENE_7_5_0 );
91
+ public static final Version V_6_6_0 = new Version (6060099 , org .apache .lucene .util .Version .LUCENE_7_6_0 );
92
+ public static final Version V_6_6_1 = new Version (6060199 , org .apache .lucene .util .Version .LUCENE_7_6_0 );
93
+ public static final Version V_6_6_2 = new Version (6060299 , org .apache .lucene .util .Version .LUCENE_7_6_0 );
94
+ public static final Version V_6_7_0 = new Version (6070099 , org .apache .lucene .util .Version .LUCENE_7_7_0 );
95
+ public static final Version V_6_7_1 = new Version (6070199 , org .apache .lucene .util .Version .LUCENE_7_7_0 );
96
+ public static final Version V_6_7_2 = new Version (6070299 , org .apache .lucene .util .Version .LUCENE_7_7_0 );
97
+ public static final Version V_6_8_0 = new Version (6080099 , org .apache .lucene .util .Version .LUCENE_7_7_0 );
98
+ public static final Version V_6_8_1 = new Version (6080199 , org .apache .lucene .util .Version .LUCENE_7_7_0 );
99
+ public static final Version V_7_0_0 = new Version (7000099 , org .apache .lucene .util .Version .LUCENE_8_0_0 );
100
+ public static final Version V_7_0_1 = new Version (7000199 , org .apache .lucene .util .Version .LUCENE_8_0_0 );
101
+ public static final Version V_7_1_0 = new Version (7010099 , org .apache .lucene .util .Version .LUCENE_8_0_0 );
102
+ public static final Version V_7_1_1 = new Version (7010199 , org .apache .lucene .util .Version .LUCENE_8_0_0 );
103
+ public static final Version V_7_1_2 = new Version (7010299 , org .apache .lucene .util .Version .LUCENE_8_0_0 );
104
+ public static final Version V_7_2_0 = new Version (7020099 , org .apache .lucene .util .Version .LUCENE_8_0_0 );
105
+
147
106
public static final Version CURRENT = V_7_2_0 ;
148
107
108
+ private static final ImmutableOpenIntMap <Version > idToVersion ;
109
+
149
110
static {
111
+ final ImmutableOpenIntMap .Builder <Version > builder = ImmutableOpenIntMap .builder ();
112
+
113
+ for (final Field declaredField : Version .class .getFields ()) {
114
+ if (declaredField .getType ().equals (Version .class )) {
115
+ final String fieldName = declaredField .getName ();
116
+ if (fieldName .equals ("CURRENT" ) || fieldName .equals ("V_EMPTY" )) {
117
+ continue ;
118
+ }
119
+ assert fieldName .matches ("V_\\ d+_\\ d+_\\ d+(_alpha[1,2]|_beta[1,2]|_rc[1,2])?" )
120
+ : "expected Version field [" + fieldName + "] to match V_\\ d+_\\ d+_\\ d+" ;
121
+ try {
122
+ final Version version = (Version ) declaredField .get (null );
123
+ if (Assertions .ENABLED ) {
124
+ final String [] fields = fieldName .split ("_" );
125
+ if (fields .length == 5 ) {
126
+ assert fields [1 ].equals ("6" ) && fields [2 ].equals ("0" ) :
127
+ "field " + fieldName + " should not have a build qualifier" ;
128
+ } else {
129
+ final int major = Integer .valueOf (fields [1 ]) * 1000000 ;
130
+ final int minor = Integer .valueOf (fields [2 ]) * 10000 ;
131
+ final int revision = Integer .valueOf (fields [3 ]) * 100 ;
132
+ final int expectedId = major + minor + revision + 99 ;
133
+ assert version .id == expectedId :
134
+ "expected version [" + fieldName + "] to have id [" + expectedId + "] but was [" + version .id + "]" ;
135
+ }
136
+ }
137
+ final Version maybePrevious = builder .put (version .id , version );
138
+ assert maybePrevious == null :
139
+ "expected [" + version .id + "] to be uniquely mapped but saw [" + maybePrevious + "] and [" + version + "]" ;
140
+ } catch (final IllegalAccessException e ) {
141
+ assert false : "Version field [" + fieldName + "] should be public" ;
142
+ }
143
+ }
144
+ }
150
145
assert CURRENT .luceneVersion .equals (org .apache .lucene .util .Version .LATEST ) : "Version must be upgraded to ["
151
146
+ org .apache .lucene .util .Version .LATEST + "] is still set to [" + CURRENT .luceneVersion + "]" ;
147
+
148
+ idToVersion = builder .build ();
152
149
}
153
150
154
151
public static Version readVersion (StreamInput in ) throws IOException {
155
152
return fromId (in .readVInt ());
156
153
}
157
154
158
155
public static Version fromId (int id ) {
156
+ if (idToVersion .containsKey (id )) {
157
+ return idToVersion .get (id );
158
+ }
159
159
switch (id ) {
160
- case V_7_2_0_ID :
161
- return V_7_2_0 ;
162
- case V_7_1_2_ID :
163
- return V_7_1_2 ;
164
- case V_7_1_1_ID :
165
- return V_7_1_1 ;
166
- case V_7_1_0_ID :
167
- return V_7_1_0 ;
168
- case V_7_0_1_ID :
169
- return V_7_0_1 ;
170
- case V_7_0_0_ID :
171
- return V_7_0_0 ;
172
- case V_6_8_1_ID :
173
- return V_6_8_1 ;
174
- case V_6_8_0_ID :
175
- return V_6_8_0 ;
176
- case V_6_7_1_ID :
177
- return V_6_7_1 ;
178
- case V_6_7_2_ID :
179
- return V_6_7_2 ;
180
- case V_6_7_0_ID :
181
- return V_6_7_0 ;
182
- case V_6_6_2_ID :
183
- return V_6_6_2 ;
184
- case V_6_6_1_ID :
185
- return V_6_6_1 ;
186
- case V_6_6_0_ID :
187
- return V_6_6_0 ;
188
- case V_6_5_4_ID :
189
- return V_6_5_4 ;
190
- case V_6_5_3_ID :
191
- return V_6_5_3 ;
192
- case V_6_5_2_ID :
193
- return V_6_5_2 ;
194
- case V_6_5_1_ID :
195
- return V_6_5_1 ;
196
- case V_6_5_0_ID :
197
- return V_6_5_0 ;
198
- case V_6_4_3_ID :
199
- return V_6_4_3 ;
200
- case V_6_4_2_ID :
201
- return V_6_4_2 ;
202
- case V_6_4_1_ID :
203
- return V_6_4_1 ;
204
- case V_6_4_0_ID :
205
- return V_6_4_0 ;
206
- case V_6_3_2_ID :
207
- return V_6_3_2 ;
208
- case V_6_3_1_ID :
209
- return V_6_3_1 ;
210
- case V_6_3_0_ID :
211
- return V_6_3_0 ;
212
- case V_6_2_4_ID :
213
- return V_6_2_4 ;
214
- case V_6_2_3_ID :
215
- return V_6_2_3 ;
216
- case V_6_2_2_ID :
217
- return V_6_2_2 ;
218
- case V_6_2_1_ID :
219
- return V_6_2_1 ;
220
- case V_6_2_0_ID :
221
- return V_6_2_0 ;
222
- case V_6_1_4_ID :
223
- return V_6_1_4 ;
224
- case V_6_1_3_ID :
225
- return V_6_1_3 ;
226
- case V_6_1_2_ID :
227
- return V_6_1_2 ;
228
- case V_6_1_1_ID :
229
- return V_6_1_1 ;
230
- case V_6_1_0_ID :
231
- return V_6_1_0 ;
232
- case V_6_0_1_ID :
233
- return V_6_0_1 ;
234
- case V_6_0_0_ID :
235
- return V_6_0_0 ;
236
- case V_6_0_0_rc2_ID :
237
- return V_6_0_0_rc2 ;
238
- case V_6_0_0_beta2_ID :
239
- return V_6_0_0_beta2 ;
240
- case V_6_0_0_rc1_ID :
241
- return V_6_0_0_rc1 ;
242
- case V_6_0_0_beta1_ID :
243
- return V_6_0_0_beta1 ;
244
- case V_6_0_0_alpha2_ID :
245
- return V_6_0_0_alpha2 ;
246
- case V_6_0_0_alpha1_ID :
247
- return V_6_0_0_alpha1 ;
248
160
case V_EMPTY_ID :
249
161
return V_EMPTY ;
250
162
default :
0 commit comments