Skip to content

Commit 2174f27

Browse files
committed
Merge remote-tracking branch 'upstream/main' into entitlements/nio-files-1
2 parents db3e499 + bf31ee6 commit 2174f27

File tree

4 files changed

+65
-24
lines changed

4 files changed

+65
-24
lines changed

libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/policy/PolicyManager.java

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import org.elasticsearch.core.Strings;
1313
import org.elasticsearch.core.SuppressForbidden;
14+
import org.elasticsearch.entitlement.bootstrap.EntitlementBootstrap;
1415
import org.elasticsearch.entitlement.bridge.EntitlementChecker;
1516
import org.elasticsearch.entitlement.instrumentation.InstrumentationService;
1617
import org.elasticsearch.entitlement.runtime.api.NotEntitledException;
@@ -218,7 +219,8 @@ private void neverEntitled(Class<?> callerClass, Supplier<String> operationDescr
218219
requestingClass.getModule().getName(),
219220
requestingClass,
220221
operationDescription.get()
221-
)
222+
),
223+
callerClass
222224
);
223225
}
224226

@@ -277,7 +279,8 @@ public void checkFileRead(Class<?> callerClass, Path path) {
277279
requestingClass.getModule().getName(),
278280
requestingClass,
279281
path
280-
)
282+
),
283+
callerClass
281284
);
282285
}
283286
}
@@ -302,7 +305,8 @@ public void checkFileWrite(Class<?> callerClass, Path path) {
302305
requestingClass.getModule().getName(),
303306
requestingClass,
304307
path
305-
)
308+
),
309+
callerClass
306310
);
307311
}
308312
}
@@ -367,14 +371,15 @@ public void checkAllNetworkAccess(Class<?> callerClass) {
367371
}
368372

369373
var classEntitlements = getEntitlements(requestingClass);
370-
checkFlagEntitlement(classEntitlements, InboundNetworkEntitlement.class, requestingClass);
371-
checkFlagEntitlement(classEntitlements, OutboundNetworkEntitlement.class, requestingClass);
374+
checkFlagEntitlement(classEntitlements, InboundNetworkEntitlement.class, requestingClass, callerClass);
375+
checkFlagEntitlement(classEntitlements, OutboundNetworkEntitlement.class, requestingClass, callerClass);
372376
}
373377

374378
private static void checkFlagEntitlement(
375379
ModuleEntitlements classEntitlements,
376380
Class<? extends Entitlement> entitlementClass,
377-
Class<?> requestingClass
381+
Class<?> requestingClass,
382+
Class<?> callerClass
378383
) {
379384
if (classEntitlements.hasEntitlement(entitlementClass) == false) {
380385
notEntitled(
@@ -384,7 +389,8 @@ private static void checkFlagEntitlement(
384389
requestingClass.getModule().getName(),
385390
requestingClass,
386391
PolicyParser.getEntitlementTypeName(entitlementClass)
387-
)
392+
),
393+
callerClass
388394
);
389395
}
390396
logger.debug(
@@ -424,12 +430,18 @@ public void checkWriteProperty(Class<?> callerClass, String property) {
424430
requestingClass.getModule().getName(),
425431
requestingClass,
426432
property
427-
)
433+
),
434+
callerClass
428435
);
429436
}
430437

431-
private static void notEntitled(String message) {
432-
throw new NotEntitledException(message);
438+
private static void notEntitled(String message, Class<?> callerClass) {
439+
var exception = new NotEntitledException(message);
440+
// don't log self tests in EntitlementBootstrap
441+
if (EntitlementBootstrap.class.equals(callerClass) == false) {
442+
logger.warn(message, exception);
443+
}
444+
throw exception;
433445
}
434446

435447
public void checkManageThreadsEntitlement(Class<?> callerClass) {
@@ -441,7 +453,7 @@ private void checkEntitlementPresent(Class<?> callerClass, Class<? extends Entit
441453
if (isTriviallyAllowed(requestingClass)) {
442454
return;
443455
}
444-
checkFlagEntitlement(getEntitlements(requestingClass), entitlementClass, requestingClass);
456+
checkFlagEntitlement(getEntitlements(requestingClass), entitlementClass, requestingClass, callerClass);
445457
}
446458

447459
ModuleEntitlements getEntitlements(Class<?> requestingClass) {

server/src/main/java/org/elasticsearch/index/IndexMode.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.elasticsearch.index.mapper.KeywordFieldMapper;
2929
import org.elasticsearch.index.mapper.MapperService;
3030
import org.elasticsearch.index.mapper.MappingLookup;
31+
import org.elasticsearch.index.mapper.MappingParserContext;
3132
import org.elasticsearch.index.mapper.MetadataFieldMapper;
3233
import org.elasticsearch.index.mapper.ProvidedIdFieldMapper;
3334
import org.elasticsearch.index.mapper.RoutingFieldMapper;
@@ -90,7 +91,7 @@ public TimestampBounds getTimestampBound(IndexMetadata indexMetadata) {
9091
}
9192

9293
@Override
93-
public MetadataFieldMapper timeSeriesIdFieldMapper() {
94+
public MetadataFieldMapper timeSeriesIdFieldMapper(MappingParserContext c) {
9495
// non time-series indices must not have a TimeSeriesIdFieldMapper
9596
return null;
9697
}
@@ -187,8 +188,8 @@ private static String routingRequiredBad() {
187188
}
188189

189190
@Override
190-
public MetadataFieldMapper timeSeriesIdFieldMapper() {
191-
return TimeSeriesIdFieldMapper.INSTANCE;
191+
public MetadataFieldMapper timeSeriesIdFieldMapper(MappingParserContext c) {
192+
return TimeSeriesIdFieldMapper.getInstance(c);
192193
}
193194

194195
@Override
@@ -277,7 +278,7 @@ public TimestampBounds getTimestampBound(IndexMetadata indexMetadata) {
277278
}
278279

279280
@Override
280-
public MetadataFieldMapper timeSeriesIdFieldMapper() {
281+
public MetadataFieldMapper timeSeriesIdFieldMapper(MappingParserContext c) {
281282
// non time-series indices must not have a TimeSeriesIdFieldMapper
282283
return null;
283284
}
@@ -348,7 +349,7 @@ public TimestampBounds getTimestampBound(IndexMetadata indexMetadata) {
348349
}
349350

350351
@Override
351-
public MetadataFieldMapper timeSeriesIdFieldMapper() {
352+
public MetadataFieldMapper timeSeriesIdFieldMapper(MappingParserContext c) {
352353
// non time-series indices must not have a TimeSeriesIdFieldMapper
353354
return null;
354355
}
@@ -518,7 +519,7 @@ public String getName() {
518519
* the _tsid field. The field mapper will be added to the list of the metadata
519520
* field mappers for the index.
520521
*/
521-
public abstract MetadataFieldMapper timeSeriesIdFieldMapper();
522+
public abstract MetadataFieldMapper timeSeriesIdFieldMapper(MappingParserContext c);
522523

523524
/**
524525
* Return an instance of the {@link TimeSeriesRoutingHashFieldMapper} that generates

server/src/main/java/org/elasticsearch/index/IndexVersions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ private static Version parseUnchecked(String version) {
147147
public static final IndexVersion UPGRADE_TO_LUCENE_10_1_0 = def(9_009_0_00, Version.LUCENE_10_1_0);
148148
public static final IndexVersion USE_SYNTHETIC_SOURCE_FOR_RECOVERY_BY_DEFAULT = def(9_010_00_0, Version.LUCENE_10_1_0);
149149
public static final IndexVersion TIMESTAMP_DOC_VALUES_SPARSE_INDEX = def(9_011_0_00, Version.LUCENE_10_1_0);
150+
public static final IndexVersion TIME_SERIES_ID_DOC_VALUES_SPARSE_INDEX = def(9_012_0_00, Version.LUCENE_10_1_0);
150151
/*
151152
* STOP! READ THIS FIRST! No, really,
152153
* ____ _____ ___ ____ _ ____ _____ _ ____ _____ _ _ ___ ____ _____ ___ ____ ____ _____ _

server/src/main/java/org/elasticsearch/index/mapper/TimeSeriesIdFieldMapper.java

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,36 @@ public class TimeSeriesIdFieldMapper extends MetadataFieldMapper {
4646
public static final String NAME = "_tsid";
4747
public static final String CONTENT_TYPE = "_tsid";
4848
public static final TimeSeriesIdFieldType FIELD_TYPE = new TimeSeriesIdFieldType();
49-
public static final TimeSeriesIdFieldMapper INSTANCE = new TimeSeriesIdFieldMapper();
49+
50+
private static final TimeSeriesIdFieldMapper INSTANCE_WITHOUT_SKIPPER = new TimeSeriesIdFieldMapper(false);
51+
private static final TimeSeriesIdFieldMapper INSTANCE_WITH_SKIPPER = new TimeSeriesIdFieldMapper(true);
52+
53+
public static TimeSeriesIdFieldMapper getInstance(boolean useDocValuesSkipper) {
54+
if (useDocValuesSkipper) {
55+
return INSTANCE_WITH_SKIPPER;
56+
} else {
57+
return INSTANCE_WITHOUT_SKIPPER;
58+
}
59+
}
60+
61+
public static TimeSeriesIdFieldMapper getInstance(MappingParserContext context) {
62+
boolean useDocValuesSkipper = context.indexVersionCreated().onOrAfter(IndexVersions.TIME_SERIES_ID_DOC_VALUES_SPARSE_INDEX)
63+
&& context.getIndexSettings().useDocValuesSkipper();
64+
return TimeSeriesIdFieldMapper.getInstance(useDocValuesSkipper);
65+
}
5066

5167
@Override
5268
public FieldMapper.Builder getMergeBuilder() {
53-
return new Builder().init(this);
69+
return new Builder(this.useDocValuesSkipper).init(this);
5470
}
5571

5672
public static class Builder extends MetadataFieldMapper.Builder {
5773

58-
protected Builder() {
74+
private final boolean useDocValuesSkipper;
75+
76+
protected Builder(boolean useDocValuesSkipper) {
5977
super(NAME);
78+
this.useDocValuesSkipper = useDocValuesSkipper;
6079
}
6180

6281
@Override
@@ -66,11 +85,11 @@ protected Parameter<?>[] getParameters() {
6685

6786
@Override
6887
public TimeSeriesIdFieldMapper build() {
69-
return INSTANCE;
88+
return TimeSeriesIdFieldMapper.getInstance(useDocValuesSkipper);
7089
}
7190
}
7291

73-
public static final TypeParser PARSER = new FixedTypeParser(c -> c.getIndexSettings().getMode().timeSeriesIdFieldMapper());
92+
public static final TypeParser PARSER = new FixedTypeParser(c -> c.getIndexSettings().getMode().timeSeriesIdFieldMapper(c));
7493

7594
public static final class TimeSeriesIdFieldType extends MappedFieldType {
7695
private TimeSeriesIdFieldType() {
@@ -115,8 +134,11 @@ public Query termQuery(Object value, SearchExecutionContext context) {
115134
}
116135
}
117136

118-
private TimeSeriesIdFieldMapper() {
137+
private final boolean useDocValuesSkipper;
138+
139+
private TimeSeriesIdFieldMapper(boolean useDocValuesSkipper) {
119140
super(FIELD_TYPE);
141+
this.useDocValuesSkipper = useDocValuesSkipper;
120142
}
121143

122144
@Override
@@ -135,7 +157,12 @@ public void postParse(DocumentParserContext context) throws IOException {
135157
} else {
136158
timeSeriesId = routingPathFields.buildHash().toBytesRef();
137159
}
138-
context.doc().add(new SortedDocValuesField(fieldType().name(), timeSeriesId));
160+
161+
if (this.useDocValuesSkipper) {
162+
context.doc().add(SortedDocValuesField.indexedField(fieldType().name(), timeSeriesId));
163+
} else {
164+
context.doc().add(new SortedDocValuesField(fieldType().name(), timeSeriesId));
165+
}
139166

140167
BytesRef uidEncoded = TsidExtractingIdFieldMapper.createField(
141168
context,

0 commit comments

Comments
 (0)