| 306 | } |
| 307 | |
| 308 | private static Version fromIdSlow(int id) { |
| 309 | // We need at least the major of the Lucene version to be correct. |
| 310 | // Our best guess is to use the same Lucene version as the previous |
| 311 | // version in the list, assuming that it didn't change. |
| 312 | List<Version> versions = DeclaredVersionsHolder.DECLARED_VERSIONS; |
| 313 | Version tmp = new Version(id, false, org.apache.lucene.util.Version.LATEST); |
| 314 | int index = Collections.binarySearch(versions, tmp); |
| 315 | if (index < 0) { |
| 316 | index = -2 - index; |
| 317 | } else { |
| 318 | assert false : "Version [" + tmp + "] is declared but absent from the switch statement in Version#fromId"; |
| 319 | } |
| 320 | final org.apache.lucene.util.Version luceneVersion; |
| 321 | if (index == -1) { |
| 322 | // this version is older than any supported version, so we |
| 323 | // assume it is the previous major to the oldest Lucene version |
| 324 | // that we know about |
| 325 | luceneVersion = org.apache.lucene.util.Version.fromBits( |
| 326 | versions.get(0).luceneVersion.major - 1, 0, 0); |
| 327 | } else { |
| 328 | // The lucene Version needs to be accurate enough for index compatibility checks. |
| 329 | // We don't know what version future CrateDB versions will ship with, but we can make assumptions: |
| 330 | // CrateDB versions 4.x will ship with Lucene 8.x |
| 331 | // CrateDB versions 5.x will likely ship with Lucene 9.x |
| 332 | Version closestVersion = versions.get(index); |
| 333 | if (closestVersion.major >= tmp.major) { |
| 334 | luceneVersion = closestVersion.luceneVersion; |
| 335 | } else { |
| 336 | luceneVersion = org.apache.lucene.util.Version.fromBits( |
| 337 | closestVersion.luceneVersion.major + 1, 0, 0); |
| 338 | } |
| 339 | } |
| 340 | return new Version(id, false, luceneVersion); |
| 341 | } |
| 342 | |
| 343 | |
| 344 | /** |