Skip to content

Commit ae5faff

Browse files
committed
Merge remote-tracking branch 'elastic/master' into sync-retention-leases
* elastic/master: Docs be explicit on how to turn off deprecated auditing (elastic#37316) Fix line length for monitor and remove suppressions (elastic#37456) Fix IndexShardTestCase.recoverReplica(IndexShard, IndexShard, boolean) (elastic#37414) Update the Flush API documentation (elastic#33551) [TEST] Muted testDifferentRolesMaintainPathOnRestart Remove dead code from ShardSearchStats (elastic#37421) Simplify testSendSnapshotSendsOps (elastic#37445) SQL: Fix issue with field names containing "." (elastic#37364) Restore lost @Inject annotation (elastic#37452)
2 parents b2b4d5b + a88c050 commit ae5faff

File tree

12 files changed

+269
-136
lines changed

12 files changed

+269
-136
lines changed

buildSrc/src/main/resources/checkstyle_suppressions.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,8 @@
4848

4949
<!-- Hopefully temporary suppression of LineLength on files that don't pass it. We should remove these when we the
5050
files start to pass. -->
51-
<suppress files="server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]monitor[/\\]jvm[/\\]GcNames.java" checks="LineLength" />
52-
<suppress files="server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]monitor[/\\]jvm[/\\]HotThreads.java" checks="LineLength" />
5351
<suppress files="server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]node[/\\]Node.java" checks="LineLength" />
5452
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]aliases[/\\]IndexAliasesIT.java" checks="LineLength" />
55-
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]monitor[/\\]jvm[/\\]JvmGcMonitorServiceSettingsTests.java" checks="LineLength" />
5653

5754
<!-- Gradle requires inputs to be seriablizable -->
5855
<suppress files="buildSrc[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]gradle[/\\]precommit[/\\]TestingConventionRule.java" checks="RegexpSinglelineJava" />

docs/reference/indices/flush.asciidoc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
== Flush
33

44
The flush API allows to flush one or more indices through an API. The
5-
flush process of an index basically frees memory from the index by
6-
flushing data to the index storage and clearing the internal
7-
<<index-modules-translog,transaction log>>. By
8-
default, Elasticsearch uses memory heuristics in order to automatically
9-
trigger flush operations as required in order to clear memory.
5+
flush process of an index makes sure that any data that is currently only
6+
persisted in the <<index-modules-translog,transaction log>> is also permanently
7+
persisted in Lucene. This reduces recovery times as that data doesn't need to be
8+
reindexed from the transaction logs after the Lucene indexed is opened. By
9+
default, Elasticsearch uses heuristics in order to automatically
10+
trigger flushes as required. It is rare for users to need to call the API directly.
1011

1112
[source,js]
1213
--------------------------------------------------

server/src/main/java/org/elasticsearch/index/search/stats/ShardSearchStats.java

Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -122,27 +122,11 @@ public void onFetchPhase(SearchContext searchContext, long tookInNanos) {
122122
});
123123
}
124124

125-
public void clear() {
126-
totalStats.clear();
127-
synchronized (this) {
128-
if (!groupsStats.isEmpty()) {
129-
MapBuilder<String, StatsHolder> typesStatsBuilder = MapBuilder.newMapBuilder();
130-
for (Map.Entry<String, StatsHolder> typeStats : groupsStats.entrySet()) {
131-
if (typeStats.getValue().totalCurrent() > 0) {
132-
typeStats.getValue().clear();
133-
typesStatsBuilder.put(typeStats.getKey(), typeStats.getValue());
134-
}
135-
}
136-
groupsStats = typesStatsBuilder.immutableMap();
137-
}
138-
}
139-
}
140-
141125
private void computeStats(SearchContext searchContext, Consumer<StatsHolder> consumer) {
142126
consumer.accept(totalStats);
143127
if (searchContext.groupStats() != null) {
144-
for (int i = 0; i < searchContext.groupStats().size(); i++) {
145-
consumer.accept(groupStats(searchContext.groupStats().get(i)));
128+
for (String group : searchContext.groupStats()) {
129+
consumer.accept(groupStats(group));
146130
}
147131
}
148132
}
@@ -184,40 +168,29 @@ public void onFreeScrollContext(SearchContext context) {
184168
}
185169

186170
static final class StatsHolder {
187-
public final MeanMetric queryMetric = new MeanMetric();
188-
public final MeanMetric fetchMetric = new MeanMetric();
171+
final MeanMetric queryMetric = new MeanMetric();
172+
final MeanMetric fetchMetric = new MeanMetric();
189173
/* We store scroll statistics in microseconds because with nanoseconds we run the risk of overflowing the total stats if there are
190174
* many scrolls. For example, on a system with 2^24 scrolls that have been executed, each executing for 2^10 seconds, then using
191175
* nanoseconds would require a numeric representation that can represent at least 2^24 * 2^10 * 10^9 > 2^24 * 2^10 * 2^29 = 2^63
192176
* which exceeds the largest value that can be represented by a long. By using microseconds, we enable capturing one-thousand
193177
* times as many scrolls (i.e., billions of scrolls which at one per second would take 32 years to occur), or scrolls that execute
194178
* for one-thousand times as long (i.e., scrolls that execute for almost twelve days on average).
195179
*/
196-
public final MeanMetric scrollMetric = new MeanMetric();
197-
public final MeanMetric suggestMetric = new MeanMetric();
198-
public final CounterMetric queryCurrent = new CounterMetric();
199-
public final CounterMetric fetchCurrent = new CounterMetric();
200-
public final CounterMetric scrollCurrent = new CounterMetric();
201-
public final CounterMetric suggestCurrent = new CounterMetric();
202-
203-
public SearchStats.Stats stats() {
180+
final MeanMetric scrollMetric = new MeanMetric();
181+
final MeanMetric suggestMetric = new MeanMetric();
182+
final CounterMetric queryCurrent = new CounterMetric();
183+
final CounterMetric fetchCurrent = new CounterMetric();
184+
final CounterMetric scrollCurrent = new CounterMetric();
185+
final CounterMetric suggestCurrent = new CounterMetric();
186+
187+
SearchStats.Stats stats() {
204188
return new SearchStats.Stats(
205189
queryMetric.count(), TimeUnit.NANOSECONDS.toMillis(queryMetric.sum()), queryCurrent.count(),
206190
fetchMetric.count(), TimeUnit.NANOSECONDS.toMillis(fetchMetric.sum()), fetchCurrent.count(),
207191
scrollMetric.count(), TimeUnit.MICROSECONDS.toMillis(scrollMetric.sum()), scrollCurrent.count(),
208192
suggestMetric.count(), TimeUnit.NANOSECONDS.toMillis(suggestMetric.sum()), suggestCurrent.count()
209193
);
210194
}
211-
212-
public long totalCurrent() {
213-
return queryCurrent.count() + fetchCurrent.count() + scrollCurrent.count() + suggestCurrent.count();
214-
}
215-
216-
public void clear() {
217-
queryMetric.clear();
218-
fetchMetric.clear();
219-
scrollMetric.clear();
220-
suggestMetric.clear();
221-
}
222195
}
223196
}

server/src/main/java/org/elasticsearch/monitor/jvm/GcNames.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,16 @@ public class GcNames {
2929
* Resolves the GC type by its memory pool name ({@link java.lang.management.MemoryPoolMXBean#getName()}.
3030
*/
3131
public static String getByMemoryPoolName(String poolName, String defaultName) {
32-
if ("Eden Space".equals(poolName) || "PS Eden Space".equals(poolName) || "Par Eden Space".equals(poolName) || "G1 Eden Space".equals(poolName)) {
32+
if ("Eden Space".equals(poolName) || "PS Eden Space".equals(poolName)
33+
|| "Par Eden Space".equals(poolName) || "G1 Eden Space".equals(poolName)) {
3334
return YOUNG;
3435
}
35-
if ("Survivor Space".equals(poolName) || "PS Survivor Space".equals(poolName) || "Par Survivor Space".equals(poolName) || "G1 Survivor Space".equals(poolName)) {
36+
if ("Survivor Space".equals(poolName) || "PS Survivor Space".equals(poolName)
37+
|| "Par Survivor Space".equals(poolName) || "G1 Survivor Space".equals(poolName)) {
3638
return SURVIVOR;
3739
}
38-
if ("Tenured Gen".equals(poolName) || "PS Old Gen".equals(poolName) || "CMS Old Gen".equals(poolName) || "G1 Old Gen".equals(poolName)) {
40+
if ("Tenured Gen".equals(poolName) || "PS Old Gen".equals(poolName)
41+
|| "CMS Old Gen".equals(poolName) || "G1 Old Gen".equals(poolName)) {
3942
return OLD;
4043
}
4144
return defaultName;
@@ -45,7 +48,8 @@ public static String getByGcName(String gcName, String defaultName) {
4548
if ("Copy".equals(gcName) || "PS Scavenge".equals(gcName) || "ParNew".equals(gcName) || "G1 Young Generation".equals(gcName)) {
4649
return YOUNG;
4750
}
48-
if ("MarkSweepCompact".equals(gcName) || "PS MarkSweep".equals(gcName) || "ConcurrentMarkSweep".equals(gcName) || "G1 Old Generation".equals(gcName)) {
51+
if ("MarkSweepCompact".equals(gcName) || "PS MarkSweep".equals(gcName)
52+
|| "ConcurrentMarkSweep".equals(gcName) || "G1 Old Generation".equals(gcName)) {
4953
return OLD;
5054
}
5155
return defaultName;

server/src/main/java/org/elasticsearch/monitor/jvm/HotThreads.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,8 @@ private String innerDetect() throws Exception {
234234
continue; // thread is not alive yet or died before the first snapshot - ignore it!
235235
}
236236
double percent = (((double) time) / interval.nanos()) * 100;
237-
sb.append(String.format(Locale.ROOT, "%n%4.1f%% (%s out of %s) %s usage by thread '%s'%n", percent, TimeValue.timeValueNanos(time), interval, type, threadName));
237+
sb.append(String.format(Locale.ROOT, "%n%4.1f%% (%s out of %s) %s usage by thread '%s'%n",
238+
percent, TimeValue.timeValueNanos(time), interval, type, threadName));
238239
// for each snapshot (2nd array index) find later snapshot for same thread with max number of
239240
// identical StackTraceElements (starting from end of each)
240241
boolean[] done = new boolean[threadElementsSnapshotCount];
@@ -267,7 +268,8 @@ private String innerDetect() throws Exception {
267268
sb.append(String.format(Locale.ROOT, " %s%n", show[l]));
268269
}
269270
} else {
270-
sb.append(String.format(Locale.ROOT, " %d/%d snapshots sharing following %d elements%n", count, threadElementsSnapshotCount, maxSim));
271+
sb.append(String.format(Locale.ROOT, " %d/%d snapshots sharing following %d elements%n",
272+
count, threadElementsSnapshotCount, maxSim));
271273
for (int l = show.length - maxSim; l < show.length; l++) {
272274
sb.append(String.format(Locale.ROOT, " %s%n", show[l]));
273275
}

server/src/test/java/org/elasticsearch/indices/recovery/RecoverySourceHandlerTests.java

Lines changed: 48 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@
7676
import org.elasticsearch.test.DummyShardLock;
7777
import org.elasticsearch.test.ESTestCase;
7878
import org.elasticsearch.test.IndexSettingsModule;
79-
import org.mockito.ArgumentCaptor;
8079

8180
import java.io.IOException;
8281
import java.io.OutputStream;
@@ -108,7 +107,6 @@
108107
import static org.mockito.Matchers.anyString;
109108
import static org.mockito.Mockito.doAnswer;
110109
import static org.mockito.Mockito.mock;
111-
import static org.mockito.Mockito.verify;
112110
import static org.mockito.Mockito.when;
113111

114112
public class RecoverySourceHandlerTests extends ESTestCase {
@@ -205,9 +203,6 @@ public void testSendSnapshotSendsOps() throws IOException {
205203
final StartRecoveryRequest request = getStartRecoveryRequest();
206204
final IndexShard shard = mock(IndexShard.class);
207205
when(shard.state()).thenReturn(IndexShardState.STARTED);
208-
final RecoveryTargetHandler recoveryTarget = mock(RecoveryTargetHandler.class);
209-
final RecoverySourceHandler handler =
210-
new RecoverySourceHandler(shard, recoveryTarget, request, fileChunkSizeInBytes, between(1, 10));
211206
final List<Translog.Operation> operations = new ArrayList<>();
212207
final int initialNumberOfDocs = randomIntBetween(16, 64);
213208
for (int i = 0; i < initialNumberOfDocs; i++) {
@@ -219,38 +214,23 @@ public void testSendSnapshotSendsOps() throws IOException {
219214
final Engine.Index index = getIndex(Integer.toString(i));
220215
operations.add(new Translog.Index(index, new Engine.IndexResult(1, 1, i - initialNumberOfDocs, true)));
221216
}
222-
operations.add(null);
223217
final long startingSeqNo = randomIntBetween(0, numberOfDocsWithValidSequenceNumbers - 1);
224218
final long requiredStartingSeqNo = randomIntBetween((int) startingSeqNo, numberOfDocsWithValidSequenceNumbers - 1);
225219
final long endingSeqNo = randomIntBetween((int) requiredStartingSeqNo - 1, numberOfDocsWithValidSequenceNumbers - 1);
226-
RecoverySourceHandler.SendSnapshotResult result = handler.phase2(startingSeqNo, requiredStartingSeqNo,
227-
endingSeqNo, new Translog.Snapshot() {
228-
@Override
229-
public void close() {
230-
231-
}
232-
233-
private int counter = 0;
234220

235-
@Override
236-
public int totalOperations() {
237-
return operations.size() - 1;
238-
}
239-
240-
@Override
241-
public Translog.Operation next() throws IOException {
242-
return operations.get(counter++);
243-
}
244-
}, randomNonNegativeLong(), randomNonNegativeLong());
221+
final List<Translog.Operation> shippedOps = new ArrayList<>();
222+
RecoveryTargetHandler recoveryTarget = new TestRecoveryTargetHandler() {
223+
@Override
224+
public long indexTranslogOperations(List<Translog.Operation> operations, int totalTranslogOps, long timestamp, long msu) {
225+
shippedOps.addAll(operations);
226+
return SequenceNumbers.NO_OPS_PERFORMED;
227+
}
228+
};
229+
RecoverySourceHandler handler = new RecoverySourceHandler(shard, recoveryTarget, request, fileChunkSizeInBytes, between(1, 10));
230+
RecoverySourceHandler.SendSnapshotResult result = handler.phase2(startingSeqNo, requiredStartingSeqNo,
231+
endingSeqNo, newTranslogSnapshot(operations, Collections.emptyList()), randomNonNegativeLong(), randomNonNegativeLong());
245232
final int expectedOps = (int) (endingSeqNo - startingSeqNo + 1);
246233
assertThat(result.totalOperations, equalTo(expectedOps));
247-
final ArgumentCaptor<List> shippedOpsCaptor = ArgumentCaptor.forClass(List.class);
248-
verify(recoveryTarget).indexTranslogOperations(shippedOpsCaptor.capture(), ArgumentCaptor.forClass(Integer.class).capture(),
249-
ArgumentCaptor.forClass(Long.class).capture(), ArgumentCaptor.forClass(Long.class).capture());
250-
List<Translog.Operation> shippedOps = new ArrayList<>();
251-
for (List list: shippedOpsCaptor.getAllValues()) {
252-
shippedOps.addAll(list);
253-
}
254234
shippedOps.sort(Comparator.comparing(Translog.Operation::seqNo));
255235
assertThat(shippedOps.size(), equalTo(expectedOps));
256236
for (int i = 0; i < shippedOps.size(); i++) {
@@ -261,30 +241,8 @@ public Translog.Operation next() throws IOException {
261241
List<Translog.Operation> requiredOps = operations.subList(0, operations.size() - 1).stream() // remove last null marker
262242
.filter(o -> o.seqNo() >= requiredStartingSeqNo && o.seqNo() <= endingSeqNo).collect(Collectors.toList());
263243
List<Translog.Operation> opsToSkip = randomSubsetOf(randomIntBetween(1, requiredOps.size()), requiredOps);
264-
expectThrows(IllegalStateException.class, () ->
265-
handler.phase2(startingSeqNo, requiredStartingSeqNo,
266-
endingSeqNo, new Translog.Snapshot() {
267-
@Override
268-
public void close() {
269-
270-
}
271-
272-
private int counter = 0;
273-
274-
@Override
275-
public int totalOperations() {
276-
return operations.size() - 1 - opsToSkip.size();
277-
}
278-
279-
@Override
280-
public Translog.Operation next() throws IOException {
281-
Translog.Operation op;
282-
do {
283-
op = operations.get(counter++);
284-
} while (op != null && opsToSkip.contains(op));
285-
return op;
286-
}
287-
}, randomNonNegativeLong(), randomNonNegativeLong()));
244+
expectThrows(IllegalStateException.class, () -> handler.phase2(startingSeqNo, requiredStartingSeqNo,
245+
endingSeqNo, newTranslogSnapshot(operations, opsToSkip), randomNonNegativeLong(), randomNonNegativeLong()));
288246
}
289247
}
290248

@@ -716,4 +674,39 @@ public void writeFileChunk(StoreFileMetaData fileMetaData, long position, BytesR
716674
int totalTranslogOps, ActionListener<Void> listener) {
717675
}
718676
}
677+
678+
private Translog.Snapshot newTranslogSnapshot(List<Translog.Operation> operations, List<Translog.Operation> operationsToSkip) {
679+
return new Translog.Snapshot() {
680+
int index = 0;
681+
int skippedCount = 0;
682+
683+
@Override
684+
public int totalOperations() {
685+
return operations.size();
686+
}
687+
688+
@Override
689+
public int skippedOperations() {
690+
return skippedCount;
691+
}
692+
693+
@Override
694+
public Translog.Operation next() {
695+
while (index < operations.size()) {
696+
Translog.Operation op = operations.get(index++);
697+
if (operationsToSkip.contains(op)) {
698+
skippedCount++;
699+
} else {
700+
return op;
701+
}
702+
}
703+
return null;
704+
}
705+
706+
@Override
707+
public void close() {
708+
709+
}
710+
};
711+
}
719712
}

0 commit comments

Comments
 (0)