Skip to content

Commit e74d021

Browse files
committed
Merge branch 'master' into netty4
* master: Fix REST test documentation [Test] move methods from bwc test to test package for use in plugins (elastic#19738) package-info.java should be in src/main only. Split regular histograms from date histograms. elastic#19551 Tighten up concurrent store metadata listing and engine writes (elastic#19684) Plugins: Make NamedWriteableRegistry immutable and add extenion point for named writeables Add documentation for the 'elasticsearch-translog' tool [TEST] Increase time waiting for all shards to move off/on to a node Fixes the active shard count check in the case of (elastic#19760) Fixes cat tasks operation in detailed mode ignore some docker craziness in scccomp environment checks
2 parents 0461e12 + 358ee7c commit e74d021

File tree

142 files changed

+2786
-1877
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+2786
-1877
lines changed

TESTING.asciidoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,18 +285,18 @@ REST tests use the following command:
285285

286286
---------------------------------------------------------------------------
287287
gradle :distribution:integ-test-zip:integTest \
288-
-Dtests.class=org.elasticsearch.test.rest.RestIT
288+
-Dtests.class=org.elasticsearch.test.rest.*Yaml*IT
289289
---------------------------------------------------------------------------
290290

291291
A specific test case can be run with
292292

293293
---------------------------------------------------------------------------
294294
gradle :distribution:integ-test-zip:integTest \
295-
-Dtests.class=org.elasticsearch.test.rest.RestIT \
295+
-Dtests.class=org.elasticsearch.test.rest.*Yaml*IT \
296296
-Dtests.method="test {p0=cat.shards/10_basic/Help}"
297297
---------------------------------------------------------------------------
298298

299-
`RestIT` are the executable test classes that runs all the
299+
`*Yaml*IT` are the executable test classes that runs all the
300300
yaml suites available within the `rest-api-spec` folder.
301301

302302
The REST tests support all the options provided by the randomized runner, plus the following:

core/src/main/java/org/elasticsearch/action/support/ActiveShardCount.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,15 @@ public boolean enoughShardsActive(final ClusterState clusterState, final String
160160
* to meet the required shard count represented by this instance.
161161
*/
162162
public boolean enoughShardsActive(final IndexShardRoutingTable shardRoutingTable) {
163+
final int activeShardCount = shardRoutingTable.activeShards().size();
163164
if (this == ActiveShardCount.ALL) {
164-
return shardRoutingTable.allShardsStarted();
165+
// adding 1 for the primary in addition to the total number of replicas,
166+
// which gives us the total number of shard copies
167+
return activeShardCount == shardRoutingTable.replicaShards().size() + 1;
165168
} else if (this == ActiveShardCount.DEFAULT) {
166-
return shardRoutingTable.primaryShard().started();
169+
return activeShardCount >= 1;
167170
} else {
168-
return shardRoutingTable.activeShards().size() >= value;
171+
return activeShardCount >= value;
169172
}
170173
}
171174

core/src/main/java/org/elasticsearch/bootstrap/Seccomp.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ static SockFilter BPF_JUMP(int code, int k, int jt, int jf) {
200200
static final int SECCOMP_RET_ALLOW = 0x7FFF0000;
201201

202202
// some errno constants for error checking/handling
203+
static final int EPERM = 0x01;
203204
static final int EACCES = 0x0D;
204205
static final int EFAULT = 0x0E;
205206
static final int EINVAL = 0x16;
@@ -275,10 +276,23 @@ private static int linuxImpl() {
275276

276277
// check that unimplemented syscalls actually return ENOSYS
277278
// you never know (e.g. https://code.google.com/p/chromium/issues/detail?id=439795)
278-
if (linux_syscall(999) >= 0 || Native.getLastError() != ENOSYS) {
279+
if (linux_syscall(999) >= 0) {
279280
throw new UnsupportedOperationException("seccomp unavailable: your kernel is buggy and you should upgrade");
280281
}
281282

283+
switch (Native.getLastError()) {
284+
case ENOSYS:
285+
break; // ok
286+
case EPERM:
287+
// NOT ok, but likely a docker container
288+
if (logger.isDebugEnabled()) {
289+
logger.debug("syscall(BOGUS) bogusly gets EPERM instead of ENOSYS");
290+
}
291+
break;
292+
default:
293+
throw new UnsupportedOperationException("seccomp unavailable: your kernel is buggy and you should upgrade");
294+
}
295+
282296
// try to check system calls really are who they claim
283297
// you never know (e.g. https://chromium.googlesource.com/chromium/src.git/+/master/sandbox/linux/seccomp-bpf/sandbox_bpf.cc#57)
284298
final int bogusArg = 0xf7a46a5c;

core/src/main/java/org/elasticsearch/client/transport/TransportClient.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ private static ClientTemplate buildTemplate(Settings providedSettings, Settings
109109
final ThreadPool threadPool = new ThreadPool(settings);
110110
resourcesToClose.add(() -> ThreadPool.terminate(threadPool, 10, TimeUnit.SECONDS));
111111
final NetworkService networkService = new NetworkService(settings, Collections.emptyList());
112-
NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry();
113112
try {
114113
final List<Setting<?>> additionalSettings = new ArrayList<>();
115114
final List<String> additionalSettingsFilter = new ArrayList<>();
@@ -120,14 +119,21 @@ private static ClientTemplate buildTemplate(Settings providedSettings, Settings
120119
}
121120
SettingsModule settingsModule = new SettingsModule(settings, additionalSettings, additionalSettingsFilter);
122121

122+
NetworkModule networkModule = new NetworkModule(networkService, settings, true);
123+
SearchModule searchModule = new SearchModule(settings, true, pluginsService.filterPlugins(SearchPlugin.class));
124+
List<NamedWriteableRegistry.Entry> entries = new ArrayList<>();
125+
entries.addAll(networkModule.getNamedWriteables());
126+
entries.addAll(searchModule.getNamedWriteables());
127+
NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(entries);
128+
123129
ModulesBuilder modules = new ModulesBuilder();
124130
// plugin modules must be added here, before others or we can get crazy injection errors...
125131
for (Module pluginModule : pluginsService.createGuiceModules()) {
126132
modules.add(pluginModule);
127133
}
128-
modules.add(new NetworkModule(networkService, settings, true, namedWriteableRegistry));
134+
modules.add(networkModule);
129135
modules.add(b -> b.bind(ThreadPool.class).toInstance(threadPool));
130-
modules.add(new SearchModule(settings, namedWriteableRegistry, true, pluginsService.filterPlugins(SearchPlugin.class)));
136+
modules.add(searchModule);
131137
ActionModule actionModule = new ActionModule(false, true, settings, null, settingsModule.getClusterSettings(),
132138
pluginsService.filterPlugins(ActionPlugin.class));
133139
modules.add(actionModule);
@@ -143,6 +149,7 @@ private static ClientTemplate buildTemplate(Settings providedSettings, Settings
143149
b.bind(BigArrays.class).toInstance(bigArrays);
144150
b.bind(PluginsService.class).toInstance(pluginsService);
145151
b.bind(CircuitBreakerService.class).toInstance(circuitBreakerService);
152+
b.bind(NamedWriteableRegistry.class).toInstance(namedWriteableRegistry);
146153
}));
147154

148155
Injector injector = modules.createInjector();

core/src/main/java/org/elasticsearch/common/geo/builders/ShapeBuilders.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@
1919

2020
package org.elasticsearch.common.geo.builders;
2121

22-
import com.vividsolutions.jts.geom.Coordinate;
23-
24-
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
25-
2622
import java.util.List;
2723

24+
import com.vividsolutions.jts.geom.Coordinate;
25+
import org.elasticsearch.common.io.stream.NamedWriteableRegistry.Entry;
26+
2827
/**
2928
* A collection of static methods for creating ShapeBuilders.
3029
*/
@@ -140,15 +139,15 @@ public static EnvelopeBuilder newEnvelope(Coordinate topLeft, Coordinate bottomR
140139
return new EnvelopeBuilder(topLeft, bottomRight);
141140
}
142141

143-
public static void register(NamedWriteableRegistry namedWriteableRegistry) {
144-
namedWriteableRegistry.register(ShapeBuilder.class, PointBuilder.TYPE.shapeName(), PointBuilder::new);
145-
namedWriteableRegistry.register(ShapeBuilder.class, CircleBuilder.TYPE.shapeName(), CircleBuilder::new);
146-
namedWriteableRegistry.register(ShapeBuilder.class, EnvelopeBuilder.TYPE.shapeName(), EnvelopeBuilder::new);
147-
namedWriteableRegistry.register(ShapeBuilder.class, MultiPointBuilder.TYPE.shapeName(), MultiPointBuilder::new);
148-
namedWriteableRegistry.register(ShapeBuilder.class, LineStringBuilder.TYPE.shapeName(), LineStringBuilder::new);
149-
namedWriteableRegistry.register(ShapeBuilder.class, MultiLineStringBuilder.TYPE.shapeName(), MultiLineStringBuilder::new);
150-
namedWriteableRegistry.register(ShapeBuilder.class, PolygonBuilder.TYPE.shapeName(), PolygonBuilder::new);
151-
namedWriteableRegistry.register(ShapeBuilder.class, MultiPolygonBuilder.TYPE.shapeName(), MultiPolygonBuilder::new);
152-
namedWriteableRegistry.register(ShapeBuilder.class, GeometryCollectionBuilder.TYPE.shapeName(), GeometryCollectionBuilder::new);
142+
public static void register(List<Entry> namedWriteables) {
143+
namedWriteables.add(new Entry(ShapeBuilder.class, PointBuilder.TYPE.shapeName(), PointBuilder::new));
144+
namedWriteables.add(new Entry(ShapeBuilder.class, CircleBuilder.TYPE.shapeName(), CircleBuilder::new));
145+
namedWriteables.add(new Entry(ShapeBuilder.class, EnvelopeBuilder.TYPE.shapeName(), EnvelopeBuilder::new));
146+
namedWriteables.add(new Entry(ShapeBuilder.class, MultiPointBuilder.TYPE.shapeName(), MultiPointBuilder::new));
147+
namedWriteables.add(new Entry(ShapeBuilder.class, LineStringBuilder.TYPE.shapeName(), LineStringBuilder::new));
148+
namedWriteables.add(new Entry(ShapeBuilder.class, MultiLineStringBuilder.TYPE.shapeName(), MultiLineStringBuilder::new));
149+
namedWriteables.add(new Entry(ShapeBuilder.class, PolygonBuilder.TYPE.shapeName(), PolygonBuilder::new));
150+
namedWriteables.add(new Entry(ShapeBuilder.class, MultiPolygonBuilder.TYPE.shapeName(), MultiPolygonBuilder::new));
151+
namedWriteables.add(new Entry(ShapeBuilder.class, GeometryCollectionBuilder.TYPE.shapeName(), GeometryCollectionBuilder::new));
153152
}
154153
}

core/src/main/java/org/elasticsearch/common/io/stream/NamedWriteableRegistry.java

Lines changed: 77 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -19,70 +19,102 @@
1919

2020
package org.elasticsearch.common.io.stream;
2121

22+
import java.util.ArrayList;
23+
import java.util.Collections;
2224
import java.util.HashMap;
25+
import java.util.List;
2326
import java.util.Map;
27+
import java.util.Objects;
28+
import java.util.stream.Collectors;
29+
import java.util.stream.Stream;
30+
31+
import org.elasticsearch.plugins.Plugin;
2432

2533
/**
26-
* Registry for {@link NamedWriteable} objects. Allows to register and retrieve prototype instances of writeable objects
27-
* given their name.
34+
* A registry for {@link org.elasticsearch.common.io.stream.Writeable.Reader} readers of {@link NamedWriteable}.
35+
*
36+
* The registration is keyed by the combination of the category class of {@link NamedWriteable}, and a name unique
37+
* to that category.
2838
*/
2939
public class NamedWriteableRegistry {
3040

31-
private final Map<Class<?>, InnerRegistry<?>> registry = new HashMap<>();
41+
/** An entry in the registry, made up of a category class and name, and a reader for that category class. */
42+
public static class Entry {
3243

33-
/**
34-
* Register a {@link NamedWriteable} given its category, its name, and a function to read it from the stream.
35-
*
36-
* This method suppresses the rawtypes warning because it intentionally using NamedWriteable instead of {@code NamedWriteable<T>} so it
37-
* is easier to use and because we might be able to drop the type parameter from NamedWriteable entirely some day.
38-
*/
39-
public synchronized <T extends NamedWriteable> void register(Class<T> categoryClass, String name,
40-
Writeable.Reader<? extends T> reader) {
41-
@SuppressWarnings("unchecked")
42-
InnerRegistry<T> innerRegistry = (InnerRegistry<T>) registry.get(categoryClass);
43-
if (innerRegistry == null) {
44-
innerRegistry = new InnerRegistry<>(categoryClass);
45-
registry.put(categoryClass, innerRegistry);
44+
/** The superclass of a {@link NamedWriteable} which will be read by {@link #reader}. */
45+
public final Class<?> categoryClass;
46+
47+
/** A name for the writeable which is unique to the {@link #categoryClass}. */
48+
public final String name;
49+
50+
/** A reader captability of reading*/
51+
public final Writeable.Reader<?> reader;
52+
53+
/** Creates a new entry which can be stored by the registry. */
54+
public <T extends NamedWriteable> Entry(Class<T> categoryClass, String name, Writeable.Reader<? extends T> reader) {
55+
this.categoryClass = Objects.requireNonNull(categoryClass);
56+
this.name = Objects.requireNonNull(name);
57+
this.reader = Objects.requireNonNull(reader);
4658
}
47-
innerRegistry.register(name, reader);
4859
}
4960

5061
/**
51-
* Returns a prototype of the {@link NamedWriteable} object identified by the name provided as argument and its category
62+
* The underlying data of the registry maps from the category to an inner
63+
* map of name unique to that category, to the actual reader.
5264
*/
53-
public synchronized <T> Writeable.Reader<? extends T> getReader(Class<T> categoryClass, String name) {
54-
@SuppressWarnings("unchecked")
55-
InnerRegistry<T> innerRegistry = (InnerRegistry<T>)registry.get(categoryClass);
56-
if (innerRegistry == null) {
57-
throw new IllegalArgumentException("unknown named writeable category [" + categoryClass.getName() + "]");
58-
}
59-
return innerRegistry.getReader(name);
60-
}
61-
62-
private static class InnerRegistry<T> {
65+
private final Map<Class<?>, Map<String, Writeable.Reader<?>>> registry;
6366

64-
private final Map<String, Writeable.Reader<? extends T>> registry = new HashMap<>();
65-
private final Class<T> categoryClass;
66-
67-
private InnerRegistry(Class<T> categoryClass) {
68-
this.categoryClass = categoryClass;
67+
/**
68+
* Constructs a new registry from the given entries.
69+
*/
70+
public NamedWriteableRegistry(List<Entry> entries) {
71+
if (entries.isEmpty()) {
72+
registry = Collections.emptyMap();
73+
return;
6974
}
75+
entries = new ArrayList<>(entries);
76+
entries.sort((e1, e2) -> e1.categoryClass.getName().compareTo(e2.categoryClass.getName()));
7077

71-
private void register(String name, Writeable.Reader<? extends T> reader) {
72-
Writeable.Reader<? extends T> existingReader = registry.get(name);
73-
if (existingReader != null) {
74-
throw new IllegalArgumentException(
75-
"named writeable [" + categoryClass.getName() + "][" + name + "] is already registered by [" + reader + "]");
78+
Map<Class<?>, Map<String, Writeable.Reader<?>>> registry = new HashMap<>();
79+
Map<String, Writeable.Reader<?>> readers = null;
80+
Class currentCategory = null;
81+
for (Entry entry : entries) {
82+
if (currentCategory != entry.categoryClass) {
83+
if (currentCategory != null) {
84+
// we've seen the last of this category, put it into the big map
85+
registry.put(currentCategory, Collections.unmodifiableMap(readers));
86+
}
87+
readers = new HashMap<>();
88+
currentCategory = entry.categoryClass;
7689
}
77-
registry.put(name, reader);
78-
}
7990

80-
private Writeable.Reader<? extends T> getReader(String name) {
81-
Writeable.Reader<? extends T> reader = registry.get(name);
82-
if (reader == null) {
83-
throw new IllegalArgumentException("unknown named writeable [" + categoryClass.getName() + "][" + name + "]");
91+
Writeable.Reader<?> oldReader = readers.put(entry.name, entry.reader);
92+
if (oldReader != null) {
93+
throw new IllegalArgumentException("NamedWriteable [" + currentCategory.getName() + "][" + entry.name + "]" +
94+
" is already registered for [" + oldReader.getClass().getName() + "]," +
95+
" cannot register [" + entry.reader.getClass().getName() + "]");
8496
}
85-
return reader;
8697
}
98+
// handle the last category
99+
registry.put(currentCategory, Collections.unmodifiableMap(readers));
100+
101+
this.registry = Collections.unmodifiableMap(registry);
102+
}
103+
104+
/**
105+
* Returns a reader for a {@link NamedWriteable} object identified by the
106+
* name provided as argument and its category.
107+
*/
108+
public <T> Writeable.Reader<? extends T> getReader(Class<T> categoryClass, String name) {
109+
Map<String, Writeable.Reader<?>> readers = registry.get(categoryClass);
110+
if (readers == null) {
111+
throw new IllegalArgumentException("Unknown NamedWriteable category [" + categoryClass.getName() + "]");
112+
}
113+
@SuppressWarnings("unchecked")
114+
Writeable.Reader<? extends T> reader = (Writeable.Reader<? extends T>)readers.get(name);
115+
if (reader == null) {
116+
throw new IllegalArgumentException("Unknown NamedWriteable [" + categoryClass.getName() + "][" + name + "]");
117+
}
118+
return reader;
87119
}
88120
}

0 commit comments

Comments
 (0)