Skip to content

Commit 42acee3

Browse files
committed
Merge branch 'master' into feature/query-refactoring
Conflicts: core/src/main/java/org/elasticsearch/index/query/IdsQueryBuilder.java
2 parents b096984 + 3bda78e commit 42acee3

File tree

22 files changed

+225
-59
lines changed

22 files changed

+225
-59
lines changed

.gitignore

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,18 @@ docs/build.log
1616
backwards/
1717

1818
## eclipse ignores (use 'mvn eclipse:eclipse' to build eclipse projects)
19-
## The only configuration files which are not ignored are certain files in
20-
## .settings (as listed below) since these files ensure common coding
21-
## style across Eclipse and IDEA.
22-
## Other files (.project, .classpath) should be generated through Maven which
23-
## will correctly set the classpath based on the declared dependencies.
19+
## All files (.project, .classpath, .settings/*) should be generated through Maven which
20+
## will correctly set the classpath based on the declared dependencies and write settings
21+
## files to ensure common coding style across Eclipse and IDEA.
2422
.project
2523
.classpath
24+
/.settings
2625
eclipse-build
2726
*/.project
2827
*/.classpath
2928
*/eclipse-build
30-
/.settings/
31-
!/.settings/org.eclipse.core.resources.prefs
32-
!/.settings/org.eclipse.jdt.core.prefs
33-
!/.settings/org.eclipse.jdt.ui.prefs
29+
*/.settings
30+
plugins/*/.settings
3431

3532
## netbeans ignores
3633
nb-configuration.xml

core/src/main/java/org/elasticsearch/common/component/AbstractComponent.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.elasticsearch.common.component;
2121

22+
import com.google.common.base.Strings;
2223
import org.elasticsearch.common.logging.DeprecationLogger;
2324
import org.elasticsearch.common.logging.ESLogger;
2425
import org.elasticsearch.common.logging.Loggers;
@@ -51,4 +52,22 @@ public AbstractComponent(Settings settings, Class customClass) {
5152
public final String nodeName() {
5253
return settings.get("name", "");
5354
}
55+
56+
/**
57+
* Checks for a deprecated setting and logs the correct alternative
58+
*/
59+
protected void logDeprecatedSetting(String settingName, String alternativeName) {
60+
if (!Strings.isNullOrEmpty(settings.get(settingName))) {
61+
deprecationLogger.deprecated("Setting [{}] is deprecated, use [{}] instead", settingName, alternativeName);
62+
}
63+
}
64+
65+
/**
66+
* Checks for a removed setting and logs the correct alternative
67+
*/
68+
protected void logRemovedSetting(String settingName, String alternativeName) {
69+
if (!Strings.isNullOrEmpty(settings.get(settingName))) {
70+
deprecationLogger.deprecated("Setting [{}] has been removed, use [{}] instead", settingName, alternativeName);
71+
}
72+
}
5473
}

core/src/main/java/org/elasticsearch/env/NodeEnvironment.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121

2222
import com.google.common.collect.ImmutableSet;
2323
import com.google.common.collect.Sets;
24+
2425
import org.apache.lucene.index.IndexWriter;
26+
import org.apache.lucene.index.SegmentInfos;
2527
import org.apache.lucene.store.*;
2628
import org.apache.lucene.util.IOUtils;
2729
import org.elasticsearch.ElasticsearchException;
@@ -116,11 +118,15 @@ public String toString() {
116118
// Setting to enable custom index.data_path setting for new indices
117119
public static final String SETTING_CUSTOM_DATA_PATH_ENABLED = "node.enable_custom_paths";
118120

121+
// If enabled, the [verbose] SegmentInfos.infoStream logging is sent to System.out:
122+
public static final String SETTING_ENABLE_LUCENE_SEGMENT_INFOS_TRACE = "node.enable_lucene_segment_infos_trace";
123+
119124
public static final String NODES_FOLDER = "nodes";
120125
public static final String INDICES_FOLDER = "indices";
121126
public static final String NODE_LOCK_FILENAME = "node.lock";
122127

123128
@Inject
129+
@SuppressForbidden(reason = "System.out.*")
124130
public NodeEnvironment(Settings settings, Environment environment) throws IOException {
125131
super(settings);
126132

@@ -186,6 +192,10 @@ public NodeEnvironment(Settings settings, Environment environment) throws IOExce
186192
}
187193

188194
maybeLogPathDetails();
195+
196+
if (settings.getAsBoolean(SETTING_ENABLE_LUCENE_SEGMENT_INFOS_TRACE, false)) {
197+
SegmentInfos.setInfoStream(System.out);
198+
}
189199
}
190200

191201
private static void releaseAndNullLocks(Lock[] locks) {

core/src/main/java/org/elasticsearch/index/query/IdsQueryBuilder.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,25 @@ public IdsQueryBuilder addIds(String... ids) {
7777
/**
7878
* Adds ids to the query.
7979
*/
80+
public IdsQueryBuilder addIds(Collection<String> ids) {
81+
this.ids.addAll(ids);
82+
return this;
83+
}
84+
85+
/**
86+
* Adds ids to the filter.
87+
*/
8088
public IdsQueryBuilder ids(String... ids) {
8189
return addIds(ids);
8290
}
8391

92+
/**
93+
* Adds ids to the filter.
94+
*/
95+
public IdsQueryBuilder ids(Collection<String> ids) {
96+
return addIds(ids);
97+
}
98+
8499
/**
85100
* Returns the ids for the query.
86101
*/

core/src/main/java/org/elasticsearch/index/shard/IndexShard.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1327,7 +1327,7 @@ private Tuple<DocumentMapper, Mapping> docMapper(String type) {
13271327
}
13281328

13291329
private final EngineConfig newEngineConfig(TranslogConfig translogConfig) {
1330-
final TranslogRecoveryPerformer translogRecoveryPerformer = new TranslogRecoveryPerformer(mapperService, mapperAnalyzer, queryParserService, indexAliasesService, indexCache) {
1330+
final TranslogRecoveryPerformer translogRecoveryPerformer = new TranslogRecoveryPerformer(shardId, mapperService, mapperAnalyzer, queryParserService, indexAliasesService, indexCache) {
13311331
@Override
13321332
protected void operationProcessed() {
13331333
assert recoveryState != null;

core/src/main/java/org/elasticsearch/index/shard/TranslogRecoveryPerformer.java

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@ public class TranslogRecoveryPerformer {
5555
private final IndexCache indexCache;
5656
private final MapperAnalyzer mapperAnalyzer;
5757
private final Map<String, Mapping> recoveredTypes = new HashMap<>();
58+
private final ShardId shardId;
5859

59-
protected TranslogRecoveryPerformer(MapperService mapperService, MapperAnalyzer mapperAnalyzer, IndexQueryParserService queryParserService, IndexAliasesService indexAliasesService, IndexCache indexCache) {
60+
protected TranslogRecoveryPerformer(ShardId shardId, MapperService mapperService, MapperAnalyzer mapperAnalyzer, IndexQueryParserService queryParserService, IndexAliasesService indexAliasesService, IndexCache indexCache) {
61+
this.shardId = shardId;
6062
this.mapperService = mapperService;
6163
this.queryParserService = queryParserService;
6264
this.indexAliasesService = indexAliasesService;
@@ -76,13 +78,33 @@ protected Tuple<DocumentMapper, Mapping> docMapper(String type) {
7678
*/
7779
int performBatchRecovery(Engine engine, Iterable<Translog.Operation> operations) {
7880
int numOps = 0;
79-
for (Translog.Operation operation : operations) {
80-
performRecoveryOperation(engine, operation, false);
81-
numOps++;
81+
try {
82+
for (Translog.Operation operation : operations) {
83+
performRecoveryOperation(engine, operation, false);
84+
numOps++;
85+
}
86+
} catch (Throwable t) {
87+
throw new BatchOperationException(shardId, "failed to apply batch translog operation [" + t.getMessage() + "]", numOps, t);
8288
}
8389
return numOps;
8490
}
8591

92+
public static class BatchOperationException extends IndexShardException {
93+
94+
private final int completedOperations;
95+
96+
public BatchOperationException(ShardId shardId, String msg, int completedOperations, Throwable cause) {
97+
super(shardId, msg, cause);
98+
this.completedOperations = completedOperations;
99+
}
100+
101+
102+
/** the number of succesful operations performed before the exception was thrown */
103+
public int completedOperations() {
104+
return completedOperations;
105+
}
106+
}
107+
86108
private void maybeAddMappingUpdate(String type, Mapping update, String docId, boolean allowMappingUpdates) {
87109
if (update == null) {
88110
return;

core/src/main/java/org/elasticsearch/indices/recovery/RecoveryState.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.elasticsearch.common.io.stream.StreamInput;
2727
import org.elasticsearch.common.io.stream.StreamOutput;
2828
import org.elasticsearch.common.io.stream.Streamable;
29-
import org.elasticsearch.common.logging.ESLoggerFactory;
3029
import org.elasticsearch.common.unit.TimeValue;
3130
import org.elasticsearch.common.xcontent.ToXContent;
3231
import org.elasticsearch.common.xcontent.XContentBuilder;
@@ -506,6 +505,13 @@ public synchronized void incrementRecoveredOperations() {
506505
assert total == UNKNOWN || total >= recovered : "total, if known, should be > recovered. total [" + total + "], recovered [" + recovered + "]";
507506
}
508507

508+
public synchronized void decrementRecoveredOperations(int ops) {
509+
recovered -= ops;
510+
assert recovered >= 0 : "recovered operations must be non-negative. Because [" + recovered + "] after decrementing [" + ops + "]";
511+
assert total == UNKNOWN || total >= recovered : "total, if known, should be > recovered. total [" + total + "], recovered [" + recovered + "]";
512+
}
513+
514+
509515
/**
510516
* returns the total number of translog operations recovered so far
511517
*/

core/src/main/java/org/elasticsearch/indices/recovery/RecoveryTarget.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,7 @@
4747
import org.elasticsearch.index.engine.RecoveryEngineException;
4848
import org.elasticsearch.index.mapper.MapperException;
4949
import org.elasticsearch.index.settings.IndexSettings;
50-
import org.elasticsearch.index.shard.IllegalIndexShardStateException;
51-
import org.elasticsearch.index.shard.IndexShard;
52-
import org.elasticsearch.index.shard.IndexShardClosedException;
53-
import org.elasticsearch.index.shard.ShardId;
50+
import org.elasticsearch.index.shard.*;
5451
import org.elasticsearch.index.store.Store;
5552
import org.elasticsearch.indices.IndexMissingException;
5653
import org.elasticsearch.indices.IndicesLifecycle;
@@ -308,10 +305,14 @@ public void messageReceived(final RecoveryTranslogOperationsRequest request, fin
308305
assert recoveryStatus.indexShard().recoveryState() == recoveryStatus.state();
309306
try {
310307
recoveryStatus.indexShard().performBatchRecovery(request.operations());
311-
} catch (MapperException mapperException) {
308+
} catch (TranslogRecoveryPerformer.BatchOperationException exception) {
309+
if (ExceptionsHelper.unwrapCause(exception) instanceof MapperException == false) {
310+
throw exception;
311+
}
312312
// in very rare cases a translog replay from primary is processed before a mapping update on this node
313313
// which causes local mapping changes. we want to wait until these mappings are processed.
314-
logger.trace("delaying recovery due to missing mapping changes", mapperException);
314+
logger.trace("delaying recovery due to missing mapping changes (rolling back stats for [{}] ops)", exception, exception.completedOperations());
315+
translog.decrementRecoveredOperations(exception.completedOperations());
315316
// we do not need to use a timeout here since the entire recovery mechanism has an inactivity protection (it will be
316317
// canceled)
317318
observer.waitForNextChange(new ClusterStateObserver.Listener() {

core/src/main/java/org/elasticsearch/rest/action/cat/RestAllocationAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void documentation(StringBuilder sb) {
5858

5959
@Override
6060
public void doRequest(final RestRequest request, final RestChannel channel, final Client client) {
61-
final String[] nodes = Strings.splitStringByCommaToArray(request.param("nodes"));
61+
final String[] nodes = Strings.splitStringByCommaToArray(request.param("nodes", "data:true"));
6262
final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
6363
clusterStateRequest.clear().routingTable(true);
6464
clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));

core/src/main/java/org/elasticsearch/rest/action/cat/RestFielddataAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public RestFielddataAction(Settings settings, RestController controller, Client
5555
@Override
5656
void doRequest(final RestRequest request, final RestChannel channel, final Client client) {
5757

58-
final NodesStatsRequest nodesStatsRequest = new NodesStatsRequest();
58+
final NodesStatsRequest nodesStatsRequest = new NodesStatsRequest("data:true");
5959
nodesStatsRequest.clear();
6060
nodesStatsRequest.indices(true);
6161
String[] fields = request.paramAsStringArray("fields", null);

0 commit comments

Comments
 (0)