Skip to content

Commit da680be

Browse files
committed
Multi data path config can cause a shard to be perceived as corrupted
Multi data path config support writes a file to a data location based on the available size (by default). There is a Lucene file called segments.gen that has the same name, and only in that case, we need to make sure we alway write it to the same data location, otherwise, the index will have multiple segments.gen files, and the shard can seem to be corrupted. The message if this case happens is that segments_xxx file was not found, in which case, a find for segments.gen can yield multiple files. Deleting the segments.gen files will cause the shard to recover properly (as its an extra protection layer to resolve the segments header by Lucene) Make sure the segments.gen file is writtne to the same directory every time fixes elastic#4674
1 parent 44a574a commit da680be

File tree

1 file changed

+6
-3
lines changed
  • src/main/java/org/elasticsearch/index/store

1 file changed

+6
-3
lines changed

src/main/java/org/elasticsearch/index/store/Store.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.google.common.collect.ImmutableList;
2323
import com.google.common.collect.ImmutableMap;
2424
import com.google.common.collect.Maps;
25+
import org.apache.lucene.index.IndexFileNames;
2526
import org.apache.lucene.store.*;
2627
import org.apache.lucene.util.IOUtils;
2728
import org.elasticsearch.common.Nullable;
@@ -426,7 +427,9 @@ public IndexOutput createOutput(String name, IOContext context) throws IOExcepti
426427
public IndexOutput createOutput(String name, IOContext context, boolean raw) throws IOException {
427428
ensureOpen();
428429
Directory directory;
429-
if (isChecksum(name)) {
430+
// we want to write the segments gen file to the same directory *all* the time
431+
// to make sure we don't create multiple copies of it
432+
if (isChecksum(name) || IndexFileNames.SEGMENTS_GEN.equals(name)) {
430433
directory = distributor.primary();
431434
} else {
432435
directory = distributor.any();
@@ -441,7 +444,7 @@ public IndexOutput createOutput(String name, IOContext context, boolean raw) thr
441444
boolean computeChecksum = !raw;
442445
if (computeChecksum) {
443446
// don't compute checksum for segment based files
444-
if ("segments.gen".equals(name) || name.startsWith("segments")) {
447+
if (IndexFileNames.SEGMENTS_GEN.equals(name) || name.startsWith(IndexFileNames.SEGMENTS)) {
445448
computeChecksum = false;
446449
}
447450
}
@@ -562,7 +565,7 @@ public void sync(Collection<String> names) throws IOException {
562565
}
563566
for (String name : names) {
564567
// write the checksums file when we sync on the segments file (committed)
565-
if (!name.equals("segments.gen") && name.startsWith("segments")) {
568+
if (!name.equals(IndexFileNames.SEGMENTS_GEN) && name.startsWith(IndexFileNames.SEGMENTS)) {
566569
writeChecksums();
567570
break;
568571
}

0 commit comments

Comments
 (0)