Skip to content

Commit bdcaec5

Browse files
authored
[Remove] types from Uid and remaining types/Uid from translog (#2450)
Removes types from UID class along with cleaning up all obsolete MapperService dependendices. This includes removing UID from the Translog Delete operation which is no longer needed due to type dependency removal. Signed-off-by: Nicholas Walter Knize <[email protected]>
1 parent 95d4750 commit bdcaec5

File tree

18 files changed

+108
-224
lines changed

18 files changed

+108
-224
lines changed

server/src/main/java/org/opensearch/index/engine/Engine.java

+2-8
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@
7272
import org.opensearch.common.unit.TimeValue;
7373
import org.opensearch.common.util.concurrent.ReleasableLock;
7474
import org.opensearch.index.VersionType;
75-
import org.opensearch.index.mapper.MapperService;
7675
import org.opensearch.index.mapper.Mapping;
7776
import org.opensearch.index.mapper.ParseContext.Document;
7877
import org.opensearch.index.mapper.ParsedDocument;
@@ -736,13 +735,8 @@ public enum SearcherScope {
736735
* Creates a new history snapshot from Lucene for reading operations whose seqno in the requesting seqno range (both inclusive).
737736
* This feature requires soft-deletes enabled. If soft-deletes are disabled, this method will throw an {@link IllegalStateException}.
738737
*/
739-
public abstract Translog.Snapshot newChangesSnapshot(
740-
String source,
741-
MapperService mapperService,
742-
long fromSeqNo,
743-
long toSeqNo,
744-
boolean requiredFullRange
745-
) throws IOException;
738+
public abstract Translog.Snapshot newChangesSnapshot(String source, long fromSeqNo, long toSeqNo, boolean requiredFullRange)
739+
throws IOException;
746740

747741
public abstract boolean hasCompleteOperationHistory(String reason, long startingSeqNo);
748742

server/src/main/java/org/opensearch/index/engine/InternalEngine.java

+1-9
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@
9191
import org.opensearch.index.VersionType;
9292
import org.opensearch.index.fieldvisitor.IdOnlyFieldVisitor;
9393
import org.opensearch.index.mapper.IdFieldMapper;
94-
import org.opensearch.index.mapper.MapperService;
9594
import org.opensearch.index.mapper.ParseContext;
9695
import org.opensearch.index.mapper.ParsedDocument;
9796
import org.opensearch.index.mapper.SeqNoFieldMapper;
@@ -2773,20 +2772,13 @@ long getNumDocUpdates() {
27732772
}
27742773

27752774
@Override
2776-
public Translog.Snapshot newChangesSnapshot(
2777-
String source,
2778-
MapperService mapperService,
2779-
long fromSeqNo,
2780-
long toSeqNo,
2781-
boolean requiredFullRange
2782-
) throws IOException {
2775+
public Translog.Snapshot newChangesSnapshot(String source, long fromSeqNo, long toSeqNo, boolean requiredFullRange) throws IOException {
27832776
ensureOpen();
27842777
refreshIfNeeded(source, toSeqNo);
27852778
Searcher searcher = acquireSearcher(source, SearcherScope.INTERNAL);
27862779
try {
27872780
LuceneChangesSnapshot snapshot = new LuceneChangesSnapshot(
27882781
searcher,
2789-
mapperService,
27902782
LuceneChangesSnapshot.DEFAULT_BATCH_SIZE,
27912783
fromSeqNo,
27922784
toSeqNo,

server/src/main/java/org/opensearch/index/engine/LuceneChangesSnapshot.java

+5-20
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.apache.lucene.index.LeafReader;
3737
import org.apache.lucene.index.LeafReaderContext;
3838
import org.apache.lucene.index.NumericDocValues;
39-
import org.apache.lucene.index.Term;
4039
import org.apache.lucene.search.BooleanClause;
4140
import org.apache.lucene.search.BooleanQuery;
4241
import org.apache.lucene.search.DocValuesFieldExistsQuery;
@@ -51,11 +50,8 @@
5150
import org.opensearch.common.lucene.Lucene;
5251
import org.opensearch.core.internal.io.IOUtils;
5352
import org.opensearch.index.fieldvisitor.FieldsVisitor;
54-
import org.opensearch.index.mapper.IdFieldMapper;
55-
import org.opensearch.index.mapper.MapperService;
5653
import org.opensearch.index.mapper.SeqNoFieldMapper;
5754
import org.opensearch.index.mapper.SourceFieldMapper;
58-
import org.opensearch.index.mapper.Uid;
5955
import org.opensearch.index.translog.Translog;
6056

6157
import java.io.Closeable;
@@ -77,7 +73,6 @@ final class LuceneChangesSnapshot implements Translog.Snapshot {
7773
private final boolean requiredFullRange;
7874

7975
private final IndexSearcher indexSearcher;
80-
private final MapperService mapperService;
8176
private int docIndex = 0;
8277
private final int totalHits;
8378
private ScoreDoc[] scoreDocs;
@@ -88,20 +83,13 @@ final class LuceneChangesSnapshot implements Translog.Snapshot {
8883
* Creates a new "translog" snapshot from Lucene for reading operations whose seq# in the specified range.
8984
*
9085
* @param engineSearcher the internal engine searcher which will be taken over if the snapshot is opened successfully
91-
* @param mapperService the mapper service which will be mainly used to resolve the document's type and uid
9286
* @param searchBatchSize the number of documents should be returned by each search
9387
* @param fromSeqNo the min requesting seq# - inclusive
9488
* @param toSeqNo the maximum requesting seq# - inclusive
9589
* @param requiredFullRange if true, the snapshot will strictly check for the existence of operations between fromSeqNo and toSeqNo
9690
*/
97-
LuceneChangesSnapshot(
98-
Engine.Searcher engineSearcher,
99-
MapperService mapperService,
100-
int searchBatchSize,
101-
long fromSeqNo,
102-
long toSeqNo,
103-
boolean requiredFullRange
104-
) throws IOException {
91+
LuceneChangesSnapshot(Engine.Searcher engineSearcher, int searchBatchSize, long fromSeqNo, long toSeqNo, boolean requiredFullRange)
92+
throws IOException {
10593
if (fromSeqNo < 0 || toSeqNo < 0 || fromSeqNo > toSeqNo) {
10694
throw new IllegalArgumentException("Invalid range; from_seqno [" + fromSeqNo + "], to_seqno [" + toSeqNo + "]");
10795
}
@@ -114,7 +102,6 @@ final class LuceneChangesSnapshot implements Translog.Snapshot {
114102
IOUtils.close(engineSearcher);
115103
}
116104
};
117-
this.mapperService = mapperService;
118105
final long requestingSize = (toSeqNo - fromSeqNo) == Long.MAX_VALUE ? Long.MAX_VALUE : (toSeqNo - fromSeqNo + 1L);
119106
this.searchBatchSize = requestingSize < searchBatchSize ? Math.toIntExact(requestingSize) : searchBatchSize;
120107
this.fromSeqNo = fromSeqNo;
@@ -278,19 +265,17 @@ private Translog.Operation readDocAsOp(int docIndex) throws IOException {
278265
: SourceFieldMapper.NAME;
279266
final FieldsVisitor fields = new FieldsVisitor(true, sourceField);
280267
leaf.reader().document(segmentDocID, fields);
281-
fields.postProcess(mapperService);
282268

283269
final Translog.Operation op;
284270
final boolean isTombstone = parallelArray.isTombStone[docIndex];
285-
if (isTombstone && fields.uid() == null) {
271+
if (isTombstone && fields.id() == null) {
286272
op = new Translog.NoOp(seqNo, primaryTerm, fields.source().utf8ToString());
287273
assert version == 1L : "Noop tombstone should have version 1L; actual version [" + version + "]";
288274
assert assertDocSoftDeleted(leaf.reader(), segmentDocID) : "Noop but soft_deletes field is not set [" + op + "]";
289275
} else {
290-
final String id = fields.uid().id();
291-
final Term uid = new Term(IdFieldMapper.NAME, Uid.encodeId(id));
276+
final String id = fields.id();
292277
if (isTombstone) {
293-
op = new Translog.Delete(id, uid, seqNo, primaryTerm, version);
278+
op = new Translog.Delete(id, seqNo, primaryTerm, version);
294279
assert assertDocSoftDeleted(leaf.reader(), segmentDocID) : "Delete op but soft_deletes field is not set [" + op + "]";
295280
} else {
296281
final BytesReference source = fields.source();

server/src/main/java/org/opensearch/index/engine/ReadOnlyEngine.java

+1-8
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import org.opensearch.common.lucene.index.OpenSearchDirectoryReader;
4747
import org.opensearch.common.util.concurrent.ReleasableLock;
4848
import org.opensearch.core.internal.io.IOUtils;
49-
import org.opensearch.index.mapper.MapperService;
5049
import org.opensearch.index.seqno.SeqNoStats;
5150
import org.opensearch.index.seqno.SequenceNumbers;
5251
import org.opensearch.index.store.Store;
@@ -326,13 +325,7 @@ public Closeable acquireHistoryRetentionLock() {
326325
}
327326

328327
@Override
329-
public Translog.Snapshot newChangesSnapshot(
330-
String source,
331-
MapperService mapperService,
332-
long fromSeqNo,
333-
long toSeqNo,
334-
boolean requiredFullRange
335-
) {
328+
public Translog.Snapshot newChangesSnapshot(String source, long fromSeqNo, long toSeqNo, boolean requiredFullRange) {
336329
return newEmptySnapshot();
337330
}
338331

server/src/main/java/org/opensearch/index/fieldvisitor/FieldsVisitor.java

+3-14
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.apache.lucene.util.BytesRef;
3737
import org.opensearch.common.bytes.BytesArray;
3838
import org.opensearch.common.bytes.BytesReference;
39-
import org.opensearch.index.mapper.DocumentMapper;
4039
import org.opensearch.index.mapper.IdFieldMapper;
4140
import org.opensearch.index.mapper.IgnoredFieldMapper;
4241
import org.opensearch.index.mapper.MappedFieldType;
@@ -67,7 +66,7 @@ public class FieldsVisitor extends StoredFieldVisitor {
6766
private final String sourceFieldName;
6867
private final Set<String> requiredFields;
6968
protected BytesReference source;
70-
protected String type, id;
69+
protected String id;
7170
protected Map<String, List<Object>> fieldsValues;
7271

7372
public FieldsVisitor(boolean loadSource) {
@@ -98,10 +97,6 @@ public Status needsField(FieldInfo fieldInfo) {
9897
}
9998

10099
public void postProcess(MapperService mapperService) {
101-
final DocumentMapper mapper = mapperService.documentMapper();
102-
if (mapper != null) {
103-
type = mapper.type();
104-
}
105100
for (Map.Entry<String, List<Object>> entry : fields().entrySet()) {
106101
MappedFieldType fieldType = mapperService.fieldType(entry.getKey());
107102
if (fieldType == null) {
@@ -167,13 +162,8 @@ public BytesReference source() {
167162
return source;
168163
}
169164

170-
public Uid uid() {
171-
if (id == null) {
172-
return null;
173-
} else if (type == null) {
174-
throw new IllegalStateException("Call postProcess before getting the uid");
175-
}
176-
return new Uid(type, id);
165+
public String id() {
166+
return id;
177167
}
178168

179169
public String routing() {
@@ -195,7 +185,6 @@ public Map<String, List<Object>> fields() {
195185
public void reset() {
196186
if (fieldsValues != null) fieldsValues.clear();
197187
source = null;
198-
type = null;
199188
id = null;
200189

201190
requiredFields.addAll(BASE_REQUIRED_FIELDS);

server/src/main/java/org/opensearch/index/mapper/Uid.java

+3-42
Original file line numberDiff line numberDiff line change
@@ -43,52 +43,13 @@ public final class Uid {
4343
public static final char DELIMITER = '#';
4444
public static final byte DELIMITER_BYTE = 0x23;
4545

46-
private final String type;
47-
48-
private final String id;
49-
50-
public Uid(String type, String id) {
51-
this.type = type;
52-
this.id = id;
53-
}
54-
55-
public String type() {
56-
return type;
57-
}
58-
59-
public String id() {
60-
return id;
61-
}
62-
63-
@Override
64-
public boolean equals(Object o) {
65-
if (this == o) return true;
66-
if (o == null || getClass() != o.getClass()) return false;
67-
68-
Uid uid = (Uid) o;
69-
70-
if (id != null ? !id.equals(uid.id) : uid.id != null) return false;
71-
if (type != null ? !type.equals(uid.type) : uid.type != null) return false;
72-
73-
return true;
74-
}
75-
76-
@Override
77-
public int hashCode() {
78-
int result = type != null ? type.hashCode() : 0;
79-
result = 31 * result + (id != null ? id.hashCode() : 0);
80-
return result;
81-
}
82-
83-
@Override
84-
public String toString() {
85-
return type + "#" + id;
86-
}
87-
8846
private static final int UTF8 = 0xff;
8947
private static final int NUMERIC = 0xfe;
9048
private static final int BASE64_ESCAPE = 0xfd;
9149

50+
// non-instantiable
51+
private Uid() {}
52+
9253
static boolean isURLBase64WithoutPadding(String id) {
9354
// We are not lenient about padding chars ('=') otherwise
9455
// 'xxx=' and 'xxx' could be considered the same id

server/src/main/java/org/opensearch/index/shard/IndexShard.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -1069,14 +1069,12 @@ private Engine.DeleteResult applyDeleteOperation(
10691069
+ getOperationPrimaryTerm()
10701070
+ "]";
10711071
ensureWriteAllowed(origin);
1072-
final Term uid = new Term(IdFieldMapper.NAME, Uid.encodeId(id));
1073-
final Engine.Delete delete = prepareDelete(id, uid, seqNo, opPrimaryTerm, version, versionType, origin, ifSeqNo, ifPrimaryTerm);
1072+
final Engine.Delete delete = prepareDelete(id, seqNo, opPrimaryTerm, version, versionType, origin, ifSeqNo, ifPrimaryTerm);
10741073
return delete(engine, delete);
10751074
}
10761075

1077-
private Engine.Delete prepareDelete(
1076+
public static Engine.Delete prepareDelete(
10781077
String id,
1079-
Term uid,
10801078
long seqNo,
10811079
long primaryTerm,
10821080
long version,
@@ -1086,6 +1084,7 @@ private Engine.Delete prepareDelete(
10861084
long ifPrimaryTerm
10871085
) {
10881086
long startTime = System.nanoTime();
1087+
final Term uid = new Term(IdFieldMapper.NAME, Uid.encodeId(id));
10891088
return new Engine.Delete(id, uid, seqNo, primaryTerm, version, versionType, origin, startTime, ifSeqNo, ifPrimaryTerm);
10901089
}
10911090

@@ -2238,7 +2237,7 @@ public Closeable acquireHistoryRetentionLock() {
22382237
* The returned snapshot can be retrieved from either Lucene index or translog files.
22392238
*/
22402239
public Translog.Snapshot getHistoryOperations(String reason, long startingSeqNo, long endSeqNo) throws IOException {
2241-
return getEngine().newChangesSnapshot(reason, mapperService, startingSeqNo, endSeqNo, true);
2240+
return getEngine().newChangesSnapshot(reason, startingSeqNo, endSeqNo, true);
22422241
}
22432242

22442243
/**
@@ -2270,7 +2269,7 @@ public long getMinRetainedSeqNo() {
22702269
* This parameter should be only enabled when the entire requesting range is below the global checkpoint.
22712270
*/
22722271
public Translog.Snapshot newChangesSnapshot(String source, long fromSeqNo, long toSeqNo, boolean requiredFullRange) throws IOException {
2273-
return getEngine().newChangesSnapshot(source, mapperService, fromSeqNo, toSeqNo, requiredFullRange);
2272+
return getEngine().newChangesSnapshot(source, fromSeqNo, toSeqNo, requiredFullRange);
22742273
}
22752274

22762275
public List<Segment> segments(boolean verbose) {

0 commit comments

Comments
 (0)