|
| 1 | +/* |
| 2 | + * Licensed to Elasticsearch under one or more contributor |
| 3 | + * license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright |
| 5 | + * ownership. Elasticsearch licenses this file to you under |
| 6 | + * the Apache License, Version 2.0 (the "License"); you may |
| 7 | + * not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.elasticsearch.index.engine; |
| 21 | + |
| 22 | +import org.apache.lucene.index.LeafReader; |
| 23 | +import org.apache.lucene.index.NumericDocValues; |
| 24 | +import org.elasticsearch.index.mapper.SeqNoFieldMapper; |
| 25 | +import org.elasticsearch.index.mapper.SourceFieldMapper; |
| 26 | +import org.elasticsearch.index.mapper.VersionFieldMapper; |
| 27 | + |
| 28 | +import java.io.IOException; |
| 29 | +import java.util.Objects; |
| 30 | + |
| 31 | +final class CombinedDocValues { |
| 32 | + private final NumericDocValues versionDV; |
| 33 | + private final NumericDocValues seqNoDV; |
| 34 | + private final NumericDocValues primaryTermDV; |
| 35 | + private final NumericDocValues tombstoneDV; |
| 36 | + private final NumericDocValues recoverySource; |
| 37 | + |
| 38 | + CombinedDocValues(LeafReader leafReader) throws IOException { |
| 39 | + this.versionDV = Objects.requireNonNull(leafReader.getNumericDocValues(VersionFieldMapper.NAME), "VersionDV is missing"); |
| 40 | + this.seqNoDV = Objects.requireNonNull(leafReader.getNumericDocValues(SeqNoFieldMapper.NAME), "SeqNoDV is missing"); |
| 41 | + this.primaryTermDV = Objects.requireNonNull( |
| 42 | + leafReader.getNumericDocValues(SeqNoFieldMapper.PRIMARY_TERM_NAME), "PrimaryTermDV is missing"); |
| 43 | + this.tombstoneDV = leafReader.getNumericDocValues(SeqNoFieldMapper.TOMBSTONE_NAME); |
| 44 | + this.recoverySource = leafReader.getNumericDocValues(SourceFieldMapper.RECOVERY_SOURCE_NAME); |
| 45 | + } |
| 46 | + |
| 47 | + long docVersion(int segmentDocId) throws IOException { |
| 48 | + assert versionDV.docID() < segmentDocId; |
| 49 | + if (versionDV.advanceExact(segmentDocId) == false) { |
| 50 | + throw new IllegalStateException("DocValues for field [" + VersionFieldMapper.NAME + "] is not found"); |
| 51 | + } |
| 52 | + return versionDV.longValue(); |
| 53 | + } |
| 54 | + |
| 55 | + long docSeqNo(int segmentDocId) throws IOException { |
| 56 | + assert seqNoDV.docID() < segmentDocId; |
| 57 | + if (seqNoDV.advanceExact(segmentDocId) == false) { |
| 58 | + throw new IllegalStateException("DocValues for field [" + SeqNoFieldMapper.NAME + "] is not found"); |
| 59 | + } |
| 60 | + return seqNoDV.longValue(); |
| 61 | + } |
| 62 | + |
| 63 | + long docPrimaryTerm(int segmentDocId) throws IOException { |
| 64 | + if (primaryTermDV == null) { |
| 65 | + return -1L; |
| 66 | + } |
| 67 | + assert primaryTermDV.docID() < segmentDocId; |
| 68 | + // Use -1 for docs which don't have primary term. The caller considers those docs as nested docs. |
| 69 | + if (primaryTermDV.advanceExact(segmentDocId) == false) { |
| 70 | + return -1; |
| 71 | + } |
| 72 | + return primaryTermDV.longValue(); |
| 73 | + } |
| 74 | + |
| 75 | + boolean isTombstone(int segmentDocId) throws IOException { |
| 76 | + if (tombstoneDV == null) { |
| 77 | + return false; |
| 78 | + } |
| 79 | + assert tombstoneDV.docID() < segmentDocId; |
| 80 | + return tombstoneDV.advanceExact(segmentDocId) && tombstoneDV.longValue() > 0; |
| 81 | + } |
| 82 | + |
| 83 | + boolean hasRecoverySource(int segmentDocId) throws IOException { |
| 84 | + if (recoverySource == null) { |
| 85 | + return false; |
| 86 | + } |
| 87 | + assert recoverySource.docID() < segmentDocId; |
| 88 | + return recoverySource.advanceExact(segmentDocId); |
| 89 | + } |
| 90 | +} |
0 commit comments