Skip to content

Commit 164af53

Browse files
committed
Merge branch 'master' into fips_licensing
2 parents b8a9c58 + 0cae19c commit 164af53

File tree

20 files changed

+211
-151
lines changed

20 files changed

+211
-151
lines changed

docs/reference/index-modules/store.asciidoc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,6 @@ process equal to the size of the file being mapped. Before using this
6767
class, be sure you have allowed plenty of
6868
<<vm-max-map-count,virtual address space>>.
6969

70-
[[default_fs]]`default_fs` deprecated[5.0.0, The `default_fs` store type is deprecated - use `fs` instead]::
71-
72-
The `default` type is deprecated and is aliased to `fs` for backward
73-
compatibility.
74-
7570
=== Pre-loading data into the file system cache
7671

7772
NOTE: This is an expert setting, the details of which may change in the future.

docs/reference/setup/sysconfig/virtual-memory.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[[vm-max-map-count]]
22
=== Virtual memory
33

4-
Elasticsearch uses a <<default_fs,`mmapfs`>> directory by
4+
Elasticsearch uses a <<mmapfs,`mmapfs`>> directory by
55
default to store its indices. The default operating system limits on mmap
66
counts is likely to be too low, which may result in out of memory exceptions.
77

modules/lang-painless/src/main/java/org/elasticsearch/painless/FunctionRef.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ public FunctionRef(PainlessLookup painlessLookup, Class<?> expected, String type
9393
* @param numCaptures number of captured arguments
9494
*/
9595
public FunctionRef(Class<?> expected, PainlessMethod interfaceMethod, PainlessMethod delegateMethod, int numCaptures) {
96-
MethodType delegateMethodType = delegateMethod.getMethodType();
96+
MethodType delegateMethodType = delegateMethod.methodType;
9797

9898
interfaceMethodName = interfaceMethod.name;
9999
factoryMethodType = MethodType.methodType(expected,
100100
delegateMethodType.dropParameterTypes(numCaptures, delegateMethodType.parameterCount()));
101-
interfaceMethodType = interfaceMethod.getMethodType().dropParameterTypes(0, 1);
101+
interfaceMethodType = interfaceMethod.methodType.dropParameterTypes(0, 1);
102102

103103
// the Painless$Script class can be inferred if owner is null
104104
if (delegateMethod.target == null) {
@@ -142,7 +142,7 @@ public FunctionRef(Class<?> expected,
142142
interfaceMethodName = interfaceMethod.name;
143143
factoryMethodType = MethodType.methodType(expected,
144144
delegateMethodType.dropParameterTypes(numCaptures, delegateMethodType.parameterCount()));
145-
interfaceMethodType = interfaceMethod.getMethodType().dropParameterTypes(0, 1);
145+
interfaceMethodType = interfaceMethod.methodType.dropParameterTypes(0, 1);
146146

147147
delegateClassName = CLASS_NAME;
148148
delegateInvokeType = H_INVOKESTATIC;

modules/lang-painless/src/main/java/org/elasticsearch/painless/lookup/PainlessLookupBuilder.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import java.lang.invoke.MethodHandle;
2929
import java.lang.invoke.MethodHandles;
30+
import java.lang.invoke.MethodType;
3031
import java.lang.reflect.Constructor;
3132
import java.lang.reflect.Field;
3233
import java.lang.reflect.Method;
@@ -356,10 +357,12 @@ public void addPainlessConstructor(Class<?> targetClass, List<Class<?>> typePara
356357
"[[" + targetCanonicalClassName + "], " + typesToCanonicalTypeNames(typeParameters) + "] not found", iae);
357358
}
358359

360+
MethodType methodType = methodHandle.type();
361+
359362
painlessConstructor = painlessMethodCache.computeIfAbsent(
360363
new PainlessMethodCacheKey(targetClass, CONSTRUCTOR_NAME, typeParameters),
361364
key -> new PainlessMethod(CONSTRUCTOR_NAME, targetClass, null, void.class, typeParameters,
362-
asmConstructor, javaConstructor.getModifiers(), methodHandle)
365+
asmConstructor, javaConstructor.getModifiers(), methodHandle, methodType)
363366
);
364367

365368
painlessClassBuilder.constructors.put(painlessMethodKey, painlessConstructor);
@@ -516,10 +519,12 @@ public void addPainlessMethod(Class<?> targetClass, Class<?> augmentedClass, Str
516519
"[" + methodName + "], " + typesToCanonicalTypeNames(typeParameters) + "] not found", iae);
517520
}
518521

522+
MethodType methodType = methodHandle.type();
523+
519524
painlessMethod = painlessMethodCache.computeIfAbsent(
520525
new PainlessMethodCacheKey(targetClass, methodName, typeParameters),
521526
key -> new PainlessMethod(methodName, targetClass, null, returnType,
522-
typeParameters, asmMethod, javaMethod.getModifiers(), methodHandle));
527+
typeParameters, asmMethod, javaMethod.getModifiers(), methodHandle, methodType));
523528

524529
painlessClassBuilder.staticMethods.put(painlessMethodKey, painlessMethod);
525530
} else if ((painlessMethod.name.equals(methodName) && painlessMethod.rtn == returnType &&
@@ -557,10 +562,12 @@ public void addPainlessMethod(Class<?> targetClass, Class<?> augmentedClass, Str
557562
}
558563
}
559564

565+
MethodType methodType = methodHandle.type();
566+
560567
painlessMethod = painlessMethodCache.computeIfAbsent(
561568
new PainlessMethodCacheKey(targetClass, methodName, typeParameters),
562569
key -> new PainlessMethod(methodName, targetClass, augmentedClass, returnType,
563-
typeParameters, asmMethod, javaMethod.getModifiers(), methodHandle));
570+
typeParameters, asmMethod, javaMethod.getModifiers(), methodHandle, methodType));
564571

565572
painlessClassBuilder.methods.put(painlessMethodKey, painlessMethod);
566573
} else if ((painlessMethod.name.equals(methodName) && painlessMethod.rtn == returnType &&

modules/lang-painless/src/main/java/org/elasticsearch/painless/lookup/PainlessMethod.java

Lines changed: 4 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ public class PainlessMethod {
3838
public final org.objectweb.asm.commons.Method method;
3939
public final int modifiers;
4040
public final MethodHandle handle;
41+
public final MethodType methodType;
4142

4243
public PainlessMethod(String name, Class<?> target, Class<?> augmentation, Class<?> rtn, List<Class<?>> arguments,
43-
org.objectweb.asm.commons.Method method, int modifiers, MethodHandle handle) {
44+
org.objectweb.asm.commons.Method method, int modifiers, MethodHandle handle, MethodType methodType) {
4445
this.name = name;
4546
this.augmentation = augmentation;
4647
this.target = target;
@@ -49,54 +50,7 @@ public PainlessMethod(String name, Class<?> target, Class<?> augmentation, Class
4950
this.method = method;
5051
this.modifiers = modifiers;
5152
this.handle = handle;
52-
}
53-
54-
/**
55-
* Returns MethodType for this method.
56-
* <p>
57-
* This works even for user-defined Methods (where the MethodHandle is null).
58-
*/
59-
public MethodType getMethodType() {
60-
// we have a methodhandle already (e.g. whitelisted class)
61-
// just return its type
62-
if (handle != null) {
63-
return handle.type();
64-
}
65-
// otherwise compute it
66-
final Class<?> params[];
67-
final Class<?> returnValue;
68-
if (augmentation != null) {
69-
// static method disguised as virtual/interface method
70-
params = new Class<?>[1 + arguments.size()];
71-
params[0] = augmentation;
72-
for (int i = 0; i < arguments.size(); i++) {
73-
params[i + 1] = PainlessLookupUtility.typeToJavaType(arguments.get(i));
74-
}
75-
returnValue = PainlessLookupUtility.typeToJavaType(rtn);
76-
} else if (Modifier.isStatic(modifiers)) {
77-
// static method: straightforward copy
78-
params = new Class<?>[arguments.size()];
79-
for (int i = 0; i < arguments.size(); i++) {
80-
params[i] = PainlessLookupUtility.typeToJavaType(arguments.get(i));
81-
}
82-
returnValue = PainlessLookupUtility.typeToJavaType(rtn);
83-
} else if ("<init>".equals(name)) {
84-
// constructor: returns the owner class
85-
params = new Class<?>[arguments.size()];
86-
for (int i = 0; i < arguments.size(); i++) {
87-
params[i] = PainlessLookupUtility.typeToJavaType(arguments.get(i));
88-
}
89-
returnValue = target;
90-
} else {
91-
// virtual/interface method: add receiver class
92-
params = new Class<?>[1 + arguments.size()];
93-
params[0] = target;
94-
for (int i = 0; i < arguments.size(); i++) {
95-
params[i + 1] = PainlessLookupUtility.typeToJavaType(arguments.get(i));
96-
}
97-
returnValue = PainlessLookupUtility.typeToJavaType(rtn);
98-
}
99-
return MethodType.methodType(returnValue, params);
53+
this.methodType = methodType;
10054
}
10155

10256
public void write(MethodWriter writer) {
@@ -118,7 +72,7 @@ public void write(MethodWriter writer) {
11872
// method since java 8 did not check, but java 9 and 10 do
11973
if (Modifier.isInterface(clazz.getModifiers())) {
12074
writer.visitMethodInsn(Opcodes.INVOKESTATIC,
121-
type.getInternalName(), name, getMethodType().toMethodDescriptorString(), true);
75+
type.getInternalName(), name, methodType.toMethodDescriptorString(), true);
12276
} else {
12377
writer.invokeStatic(type, method);
12478
}

modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFunction.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,11 @@ void generateSignature(PainlessLookup painlessLookup) {
145145
}
146146
}
147147

148+
int modifiers = Modifier.STATIC | Modifier.PRIVATE;
148149
org.objectweb.asm.commons.Method method = new org.objectweb.asm.commons.Method(name, MethodType.methodType(
149150
PainlessLookupUtility.typeToJavaType(rtnType), paramClasses).toMethodDescriptorString());
150-
this.method = new PainlessMethod(name, null, null, rtnType, paramTypes, method, Modifier.STATIC | Modifier.PRIVATE, null);
151+
MethodType methodType = MethodType.methodType(PainlessLookupUtility.typeToJavaType(rtnType), paramClasses);
152+
this.method = new PainlessMethod(name, null, null, rtnType, paramTypes, method, modifiers, null, methodType);
151153
}
152154

153155
@Override

server/src/main/java/org/elasticsearch/index/get/GetResult.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.elasticsearch.index.get;
2121

2222
import org.elasticsearch.ElasticsearchParseException;
23+
import org.elasticsearch.common.Strings;
2324
import org.elasticsearch.common.bytes.BytesReference;
2425
import org.elasticsearch.common.compress.CompressorFactory;
2526
import org.elasticsearch.common.document.DocumentField;
@@ -30,6 +31,7 @@
3031
import org.elasticsearch.common.xcontent.XContentBuilder;
3132
import org.elasticsearch.common.xcontent.XContentHelper;
3233
import org.elasticsearch.common.xcontent.XContentParser;
34+
import org.elasticsearch.index.mapper.IgnoredFieldMapper;
3335
import org.elasticsearch.index.mapper.SourceFieldMapper;
3436
import org.elasticsearch.search.lookup.SourceLookup;
3537

@@ -225,10 +227,13 @@ public XContentBuilder toXContentEmbedded(XContentBuilder builder, Params params
225227
}
226228
}
227229
}
228-
229230
for (DocumentField field : metaFields) {
230-
Object value = field.getValue();
231-
builder.field(field.getName(), value);
231+
// TODO: can we avoid having an exception here?
232+
if (field.getName().equals(IgnoredFieldMapper.NAME)) {
233+
builder.field(field.getName(), field.getValues());
234+
} else {
235+
builder.field(field.getName(), field.<Object>getValue());
236+
}
232237
}
233238

234239
builder.field(FOUND, exists);
@@ -316,7 +321,11 @@ public static GetResult fromXContentEmbedded(XContentParser parser, String index
316321
parser.skipChildren(); // skip potential inner objects for forward compatibility
317322
}
318323
} else if (token == XContentParser.Token.START_ARRAY) {
319-
parser.skipChildren(); // skip potential inner arrays for forward compatibility
324+
if (IgnoredFieldMapper.NAME.equals(currentFieldName)) {
325+
fields.put(currentFieldName, new DocumentField(currentFieldName, parser.list()));
326+
} else {
327+
parser.skipChildren(); // skip potential inner arrays for forward compatibility
328+
}
320329
}
321330
}
322331
return new GetResult(index, type, id, version, found, source, fields);
@@ -400,7 +409,12 @@ public boolean equals(Object o) {
400409

401410
@Override
402411
public int hashCode() {
403-
return Objects.hash(index, type, id, version, exists, fields, sourceAsMap());
412+
return Objects.hash(version, exists, index, type, id, fields, sourceAsMap());
413+
}
414+
415+
@Override
416+
public String toString() {
417+
return Strings.toString(this, true, true);
404418
}
405419
}
406420

server/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,12 @@ private void removeShards(final ClusterState state) {
420420
// state may result in a new shard being initialized while having the same allocation id as the currently started shard.
421421
logger.debug("{} removing shard (not active, current {}, new {})", shardId, currentRoutingEntry, newShardRouting);
422422
indexService.removeShard(shardId.id(), "removing shard (stale copy)");
423+
} else if (newShardRouting.primary() && currentRoutingEntry.primary() == false && newShardRouting.initializing()) {
424+
assert currentRoutingEntry.initializing() : currentRoutingEntry; // see above if clause
425+
// this can happen when cluster state batching batches activation of the shard, closing an index, reopening it
426+
// and assigning an initializing primary to this node
427+
logger.debug("{} removing shard (not active, current {}, new {})", shardId, currentRoutingEntry, newShardRouting);
428+
indexService.removeShard(shardId.id(), "removing shard (stale copy)");
423429
}
424430
}
425431
}

server/src/main/java/org/elasticsearch/search/SearchHit.java

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -602,16 +602,24 @@ private static void declareMetaDataFields(ObjectParser<Map<String, Object>, Void
602602
for (String metadatafield : MapperService.getAllMetaFields()) {
603603
if (metadatafield.equals(Fields._ID) == false && metadatafield.equals(Fields._INDEX) == false
604604
&& metadatafield.equals(Fields._TYPE) == false) {
605-
parser.declareField((map, field) -> {
606-
@SuppressWarnings("unchecked")
607-
Map<String, DocumentField> fieldMap = (Map<String, DocumentField>) map.computeIfAbsent(Fields.FIELDS,
608-
v -> new HashMap<String, DocumentField>());
609-
fieldMap.put(field.getName(), field);
610-
}, (p, c) -> {
611-
List<Object> values = new ArrayList<>();
612-
values.add(parseFieldsValue(p));
613-
return new DocumentField(metadatafield, values);
614-
}, new ParseField(metadatafield), ValueType.VALUE);
605+
if (metadatafield.equals(IgnoredFieldMapper.NAME)) {
606+
parser.declareObjectArray((map, list) -> {
607+
@SuppressWarnings("unchecked")
608+
Map<String, DocumentField> fieldMap = (Map<String, DocumentField>) map.computeIfAbsent(Fields.FIELDS,
609+
v -> new HashMap<String, DocumentField>());
610+
DocumentField field = new DocumentField(metadatafield, list);
611+
fieldMap.put(field.getName(), field);
612+
}, (p, c) -> parseFieldsValue(p),
613+
new ParseField(metadatafield));
614+
} else {
615+
parser.declareField((map, field) -> {
616+
@SuppressWarnings("unchecked")
617+
Map<String, DocumentField> fieldMap = (Map<String, DocumentField>) map.computeIfAbsent(Fields.FIELDS,
618+
v -> new HashMap<String, DocumentField>());
619+
fieldMap.put(field.getName(), field);
620+
}, (p, c) -> new DocumentField(metadatafield, Collections.singletonList(parseFieldsValue(p))),
621+
new ParseField(metadatafield), ValueType.VALUE);
622+
}
615623
}
616624
}
617625
}
@@ -958,4 +966,9 @@ public int hashCode() {
958966
return Objects.hash(field, offset, child);
959967
}
960968
}
969+
970+
@Override
971+
public String toString() {
972+
return Strings.toString(this, true, true);
973+
}
961974
}

0 commit comments

Comments
 (0)