Skip to content

Commit 00fc7bf

Browse files
committed
Avoid multiline check-index log messages
Today we filter out multiline log messages on Windows, preventing us from asserting that they are emitted. This commit replaces some multi-line log messages with multiple single-line log messages to fix `IndexShardTests#testIndexCheckOnStartup` on Windows. Relates elastic#74233 Closes elastic#74299
1 parent 331a44b commit 00fc7bf

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

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

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2575,8 +2575,6 @@ private void doCheckIndex() throws IOException {
25752575
if (Lucene.indexExists(store.directory()) == false) {
25762576
return;
25772577
}
2578-
BytesStreamOutput os = new BytesStreamOutput();
2579-
PrintStream out = new PrintStream(os, false, StandardCharsets.UTF_8.name());
25802578

25812579
if ("checksum".equals(checkIndexOnStartup)) {
25822580
// physical verification only: verify all checksums for the latest commit
@@ -2588,23 +2586,36 @@ private void doCheckIndex() throws IOException {
25882586
logger.warn("check index [failure]", e);
25892587
throw e;
25902588
}
2589+
final List<String> checkedFiles = new ArrayList<>(metadata.size());
25912590
for (Map.Entry<String, StoreFileMetadata> entry : metadata.asMap().entrySet()) {
25922591
try {
25932592
Store.checkIntegrity(entry.getValue(), store.directory());
2594-
out.println("checksum passed: " + entry.getKey());
2595-
} catch (IOException exc) {
2596-
out.println("checksum failed: " + entry.getKey());
2597-
exc.printStackTrace(out);
2598-
corrupt = exc;
2593+
if (corrupt == null) {
2594+
checkedFiles.add(entry.getKey());
2595+
} else {
2596+
logger.info("check index [ok]: checksum check passed on [{}]", entry.getKey());
2597+
}
2598+
} catch (IOException ioException) {
2599+
for (final String checkedFile : checkedFiles) {
2600+
logger.info("check index [ok]: checksum check passed on [{}]", checkedFile);
2601+
}
2602+
checkedFiles.clear();
2603+
logger.warn(new ParameterizedMessage("check index [failure]: checksum failed on [{}]", entry.getKey()), ioException);
2604+
corrupt = ioException;
25992605
}
26002606
}
2601-
out.flush();
26022607
if (corrupt != null) {
2603-
logger.warn("check index [failure]\n{}", os.bytes().utf8ToString());
26042608
throw corrupt;
26052609
}
2610+
if (logger.isDebugEnabled()) {
2611+
for (final String checkedFile : checkedFiles) {
2612+
logger.debug("check index [ok]: checksum check passed on [{}]", checkedFile);
2613+
}
2614+
}
26062615
} else {
26072616
// full checkindex
2617+
final BytesStreamOutput os = new BytesStreamOutput();
2618+
final PrintStream out = new PrintStream(os, false, StandardCharsets.UTF_8.name());
26082619
final CheckIndex.Status status = store.checkIndex(out);
26092620
out.flush();
26102621
if (status.clean == false) {
@@ -2617,10 +2628,10 @@ private void doCheckIndex() throws IOException {
26172628
logger.warn("{}", os.bytes().utf8ToString());
26182629
throw new IOException("index check failure");
26192630
}
2620-
}
26212631

2622-
if (logger.isDebugEnabled()) {
2623-
logger.debug("check index [success]\n{}", os.bytes().utf8ToString());
2632+
if (logger.isDebugEnabled()) {
2633+
logger.debug("check index [success]\n{}", os.bytes().utf8ToString());
2634+
}
26242635
}
26252636

26262637
recoveryState.getVerifyIndex().checkIndexTime(Math.max(0, TimeValue.nsecToMSec(System.nanoTime() - timeNS)));

0 commit comments

Comments
 (0)