|
22 | 22 | import org.apache.lucene.index.*;
|
23 | 23 | import org.apache.lucene.util.Bits;
|
24 | 24 | import org.apache.lucene.util.BytesRef;
|
| 25 | +import org.elasticsearch.Version; |
25 | 26 | import org.elasticsearch.common.Numbers;
|
| 27 | +import org.elasticsearch.common.io.stream.StreamInput; |
| 28 | +import org.elasticsearch.common.io.stream.StreamOutput; |
26 | 29 | import org.elasticsearch.index.mapper.internal.UidFieldMapper;
|
27 | 30 | import org.elasticsearch.index.mapper.internal.VersionFieldMapper;
|
28 | 31 |
|
|
32 | 35 | /** Utility class to resolve the Lucene doc ID and version for a given uid. */
|
33 | 36 | public class Versions {
|
34 | 37 |
|
35 |
| - public static final long MATCH_ANY = 0L; // Version was not specified by the user |
| 38 | + public static final long MATCH_ANY = -3L; // Version was not specified by the user |
| 39 | + // the value for MATCH_ANY before ES 1.2.0 - will be removed |
| 40 | + public static final long MATCH_ANY_PRE_1_2_0 = 0L; |
36 | 41 | public static final long NOT_FOUND = -1L;
|
37 | 42 | public static final long NOT_SET = -2L;
|
38 | 43 |
|
39 |
| - private Versions() {} |
| 44 | + public static void writeVersion(long version, StreamOutput out) throws IOException { |
| 45 | + if (out.getVersion().before(Version.V_1_2_0) && version == MATCH_ANY) { |
| 46 | + // we have to send out a value the node will understand |
| 47 | + version = MATCH_ANY_PRE_1_2_0; |
| 48 | + } |
| 49 | + out.writeLong(version); |
| 50 | + } |
| 51 | + |
| 52 | + public static long readVersion(StreamInput in) throws IOException { |
| 53 | + long version = in.readLong(); |
| 54 | + if (in.getVersion().before(Version.V_1_2_0) && version == MATCH_ANY_PRE_1_2_0) { |
| 55 | + version = MATCH_ANY; |
| 56 | + } |
| 57 | + return version; |
| 58 | + } |
| 59 | + |
| 60 | + public static void writeVersionWithVLongForBW(long version, StreamOutput out) throws IOException { |
| 61 | + if (out.getVersion().onOrAfter(Version.V_1_2_0)) { |
| 62 | + out.writeLong(version); |
| 63 | + return; |
| 64 | + } |
| 65 | + |
| 66 | + if (version == MATCH_ANY) { |
| 67 | + // we have to send out a value the node will understand |
| 68 | + version = MATCH_ANY_PRE_1_2_0; |
| 69 | + } |
| 70 | + out.writeVLong(version); |
| 71 | + } |
| 72 | + |
| 73 | + public static long readVersionWithVLongForBW(StreamInput in) throws IOException { |
| 74 | + if (in.getVersion().onOrAfter(Version.V_1_2_0)) { |
| 75 | + return in.readLong(); |
| 76 | + } else { |
| 77 | + long version = in.readVLong(); |
| 78 | + if (version == MATCH_ANY_PRE_1_2_0) { |
| 79 | + return MATCH_ANY; |
| 80 | + } |
| 81 | + return version; |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + private Versions() { |
| 86 | + } |
40 | 87 |
|
41 | 88 | /** Wraps an {@link AtomicReaderContext}, a doc ID <b>relative to the context doc base</b> and a version. */
|
42 | 89 | public static class DocIdAndVersion {
|
|
0 commit comments