diff --git a/core/src/main/java/org/elasticsearch/index/snapshots/blobstore/BlobStoreIndexShardRepository.java b/core/src/main/java/org/elasticsearch/index/snapshots/blobstore/BlobStoreIndexShardRepository.java
index 604ac1b2d1d..330787a68a3 100644
--- a/core/src/main/java/org/elasticsearch/index/snapshots/blobstore/BlobStoreIndexShardRepository.java
+++ b/core/src/main/java/org/elasticsearch/index/snapshots/blobstore/BlobStoreIndexShardRepository.java
@@ -926,13 +926,6 @@ public class BlobStoreIndexShardRepository extends AbstractComponent implements
}
Store.verify(indexOutput);
indexOutput.close();
- // write the checksum
- if (fileInfo.metadata().hasLegacyChecksum()) {
- Store.LegacyChecksums legacyChecksums = new Store.LegacyChecksums();
- legacyChecksums.add(fileInfo.metadata());
- legacyChecksums.write(store);
-
- }
store.directory().sync(Collections.singleton(fileInfo.physicalName()));
success = true;
} catch (CorruptIndexException | IndexFormatTooOldException | IndexFormatTooNewException ex) {
diff --git a/core/src/main/java/org/elasticsearch/index/snapshots/blobstore/BlobStoreIndexShardSnapshot.java b/core/src/main/java/org/elasticsearch/index/snapshots/blobstore/BlobStoreIndexShardSnapshot.java
index 6452778964b..08af2843ce4 100644
--- a/core/src/main/java/org/elasticsearch/index/snapshots/blobstore/BlobStoreIndexShardSnapshot.java
+++ b/core/src/main/java/org/elasticsearch/index/snapshots/blobstore/BlobStoreIndexShardSnapshot.java
@@ -180,7 +180,6 @@ public class BlobStoreIndexShardSnapshot implements ToXContent, FromXContentBuil
*
* @return file checksum
*/
- @Nullable
public String checksum() {
return metadata.checksum();
}
diff --git a/core/src/main/java/org/elasticsearch/index/store/LegacyVerification.java b/core/src/main/java/org/elasticsearch/index/store/LegacyVerification.java
deleted file mode 100644
index d2b0a2815e9..00000000000
--- a/core/src/main/java/org/elasticsearch/index/store/LegacyVerification.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Licensed to Elasticsearch under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.elasticsearch.index.store;
-
-import org.apache.lucene.index.CorruptIndexException;
-import org.apache.lucene.store.BufferedChecksum;
-import org.apache.lucene.store.IndexOutput;
-
-import java.io.IOException;
-import java.util.zip.Adler32;
-import java.util.zip.Checksum;
-
-/**
- * Implements verification checks to the best extent possible
- * against legacy segments.
- *
- * For files since ES 1.3, we have a lucene checksum, and
- * we verify both CRC32 + length from that.
- * For older segment files, we have an elasticsearch Adler32 checksum
- * and a length, except for commit points.
- * For older commit points, we only have the length in metadata,
- * but lucene always wrote a CRC32 checksum we can verify in the future, too.
- * For (Jurassic?) files, we dont have an Adler32 checksum at all,
- * since its optional in the protocol. But we always know the length.
- * @deprecated only to support old segments
- */
-@Deprecated
-class LegacyVerification {
-
- // TODO: add a verifier for old lucene segments_N that also checks CRC.
- // but for now, at least truncation is detected here (as length will be checked)
-
- /**
- * verifies Adler32 + length for index files before lucene 4.8
- */
- static class Adler32VerifyingIndexOutput extends VerifyingIndexOutput {
- final String adler32;
- final long length;
- final Checksum checksum = new BufferedChecksum(new Adler32());
- long written;
-
- public Adler32VerifyingIndexOutput(IndexOutput out, String adler32, long length) {
- super(out);
- this.adler32 = adler32;
- this.length = length;
- }
-
- @Override
- public void verify() throws IOException {
- if (written != length) {
- throw new CorruptIndexException("expected length=" + length + " != actual length: " + written + " : file truncated?", out.toString());
- }
- final String actualChecksum = Store.digestToString(checksum.getValue());
- if (!adler32.equals(actualChecksum)) {
- throw new CorruptIndexException("checksum failed (hardware problem?) : expected=" + adler32 +
- " actual=" + actualChecksum, out.toString());
- }
- }
-
- @Override
- public void writeByte(byte b) throws IOException {
- out.writeByte(b);
- checksum.update(b);
- written++;
- }
-
- @Override
- public void writeBytes(byte[] bytes, int offset, int length) throws IOException {
- out.writeBytes(bytes, offset, length);
- checksum.update(bytes, offset, length);
- written += length;
- }
- }
-
- /**
- * verifies length for index files before lucene 4.8
- */
- static class LengthVerifyingIndexOutput extends VerifyingIndexOutput {
- final long length;
- long written;
-
- public LengthVerifyingIndexOutput(IndexOutput out, long length) {
- super(out);
- this.length = length;
- }
-
- @Override
- public void verify() throws IOException {
- if (written != length) {
- throw new CorruptIndexException("expected length=" + length + " != actual length: " + written + " : file truncated?", out.toString());
- }
- }
-
- @Override
- public void writeByte(byte b) throws IOException {
- out.writeByte(b);
- written++;
- }
-
- @Override
- public void writeBytes(byte[] bytes, int offset, int length) throws IOException {
- out.writeBytes(bytes, offset, length);
- written += length;
- }
- }
-}
diff --git a/core/src/main/java/org/elasticsearch/index/store/Store.java b/core/src/main/java/org/elasticsearch/index/store/Store.java
index deeb3daad51..77e7f32f5f5 100644
--- a/core/src/main/java/org/elasticsearch/index/store/Store.java
+++ b/core/src/main/java/org/elasticsearch/index/store/Store.java
@@ -118,8 +118,6 @@ import static java.util.Collections.unmodifiableMap;
*
*/
public class Store extends AbstractIndexShardComponent implements Closeable, RefCounted {
- private static final Version FIRST_LUCENE_CHECKSUM_VERSION = Version.LUCENE_4_8_0;
-
static final String CODEC = "store";
static final int VERSION_WRITE_THROWABLE= 2; // we write throwable since 2.0
static final int VERSION_STACK_TRACE = 1; // we write the stack trace too since 1.4.0
@@ -456,19 +454,9 @@ public class Store extends AbstractIndexShardComponent implements Closeable, Ref
IndexOutput output = directory().createOutput(fileName, context);
boolean success = false;
try {
- if (metadata.hasLegacyChecksum()) {
- logger.debug("create legacy adler32 output for {}", fileName);
- output = new LegacyVerification.Adler32VerifyingIndexOutput(output, metadata.checksum(), metadata.length());
- } else if (metadata.checksum() == null) {
- // TODO: when the file is a segments_N, we can still CRC-32 + length for more safety
- // its had that checksum forever.
- logger.debug("create legacy length-only output for {}", fileName);
- output = new LegacyVerification.LengthVerifyingIndexOutput(output, metadata.length());
- } else {
- assert metadata.writtenBy() != null;
- assert metadata.writtenBy().onOrAfter(FIRST_LUCENE_CHECKSUM_VERSION);
- output = new LuceneVerifyingIndexOutput(metadata, output);
- }
+ assert metadata.writtenBy() != null;
+ assert metadata.writtenBy().onOrAfter(StoreFileMetaData.FIRST_LUCENE_CHECKSUM_VERSION);
+ output = new LuceneVerifyingIndexOutput(metadata, output);
success = true;
} finally {
if (success == false) {
@@ -485,12 +473,8 @@ public class Store extends AbstractIndexShardComponent implements Closeable, Ref
}
public IndexInput openVerifyingInput(String filename, IOContext context, StoreFileMetaData metadata) throws IOException {
- if (metadata.hasLegacyChecksum() || metadata.checksum() == null) {
- logger.debug("open legacy input for {}", filename);
- return directory().openInput(filename, context);
- }
assert metadata.writtenBy() != null;
- assert metadata.writtenBy().onOrAfter(FIRST_LUCENE_CHECKSUM_VERSION);
+ assert metadata.writtenBy().onOrAfter(StoreFileMetaData.FIRST_LUCENE_CHECKSUM_VERSION);
return new VerifyingIndexInput(directory().openInput(filename, context));
}
@@ -518,32 +502,12 @@ public class Store extends AbstractIndexShardComponent implements Closeable, Ref
if (input.length() != md.length()) { // first check the length no matter how old this file is
throw new CorruptIndexException("expected length=" + md.length() + " != actual length: " + input.length() + " : file truncated?", input);
}
- if (md.writtenBy() != null && md.writtenBy().onOrAfter(FIRST_LUCENE_CHECKSUM_VERSION)) {
- // throw exception if the file is corrupt
- String checksum = Store.digestToString(CodecUtil.checksumEntireFile(input));
- // throw exception if metadata is inconsistent
- if (!checksum.equals(md.checksum())) {
- throw new CorruptIndexException("inconsistent metadata: lucene checksum=" + checksum +
- ", metadata checksum=" + md.checksum(), input);
- }
- } else if (md.hasLegacyChecksum()) {
- // legacy checksum verification - no footer that we need to omit in the checksum!
- final Checksum checksum = new Adler32();
- final byte[] buffer = new byte[md.length() > 4096 ? 4096 : (int) md.length()];
- final long len = input.length();
- long read = 0;
- while (len > read) {
- final long bytesLeft = len - read;
- final int bytesToRead = bytesLeft < buffer.length ? (int) bytesLeft : buffer.length;
- input.readBytes(buffer, 0, bytesToRead, false);
- checksum.update(buffer, 0, bytesToRead);
- read += bytesToRead;
- }
- String adler32 = Store.digestToString(checksum.getValue());
- if (!adler32.equals(md.checksum())) {
- throw new CorruptIndexException("checksum failed (hardware problem?) : expected=" + md.checksum() +
- " actual=" + adler32, input);
- }
+ // throw exception if the file is corrupt
+ String checksum = Store.digestToString(CodecUtil.checksumEntireFile(input));
+ // throw exception if metadata is inconsistent
+ if (!checksum.equals(md.checksum())) {
+ throw new CorruptIndexException("inconsistent metadata: lucene checksum=" + checksum +
+ ", metadata checksum=" + md.checksum(), input);
}
}
}
@@ -799,7 +763,7 @@ public class Store extends AbstractIndexShardComponent implements Closeable, Ref
final int size = in.readVInt();
Map metadata = new HashMap<>();
for (int i = 0; i < size; i++) {
- StoreFileMetaData meta = StoreFileMetaData.readStoreFileMetaData(in);
+ StoreFileMetaData meta = new StoreFileMetaData(in);
metadata.put(meta.name(), meta);
}
Map commitUserData = new HashMap<>();
@@ -836,14 +800,13 @@ public class Store extends AbstractIndexShardComponent implements Closeable, Ref
static LoadedMetadata loadMetadata(IndexCommit commit, Directory directory, ESLogger logger) throws IOException {
long numDocs;
Map builder = new HashMap<>();
- Map checksumMap = readLegacyChecksums(directory).v1();
Map commitUserDataBuilder = new HashMap<>();
try {
final SegmentInfos segmentCommitInfos = Store.readSegmentsInfo(commit, directory);
numDocs = Lucene.getNumDocs(segmentCommitInfos);
commitUserDataBuilder.putAll(segmentCommitInfos.getUserData());
@SuppressWarnings("deprecation")
- Version maxVersion = Version.LUCENE_4_0; // we don't know which version was used to write so we take the max version.
+ Version maxVersion = segmentCommitInfos.getMinSegmentLuceneVersion(); // we don't know which version was used to write so we take the max version.
for (SegmentCommitInfo info : segmentCommitInfos) {
final Version version = info.info.getVersion();
if (version == null) {
@@ -854,26 +817,21 @@ public class Store extends AbstractIndexShardComponent implements Closeable, Ref
maxVersion = version;
}
for (String file : info.files()) {
- String legacyChecksum = checksumMap.get(file);
- if (version.onOrAfter(FIRST_LUCENE_CHECKSUM_VERSION)) {
+ if (version.onOrAfter(StoreFileMetaData.FIRST_LUCENE_CHECKSUM_VERSION)) {
checksumFromLuceneFile(directory, file, builder, logger, version, SEGMENT_INFO_EXTENSION.equals(IndexFileNames.getExtension(file)));
} else {
- builder.put(file, new StoreFileMetaData(file, directory.fileLength(file), legacyChecksum, version));
+ throw new IllegalStateException("version must be onOrAfter: " + StoreFileMetaData.FIRST_LUCENE_CHECKSUM_VERSION + " but was: " + version);
}
}
}
+ if (maxVersion == null) {
+ maxVersion = StoreFileMetaData.FIRST_LUCENE_CHECKSUM_VERSION;
+ }
final String segmentsFile = segmentCommitInfos.getSegmentsFileName();
- String legacyChecksum = checksumMap.get(segmentsFile);
- if (maxVersion.onOrAfter(FIRST_LUCENE_CHECKSUM_VERSION)) {
+ if (maxVersion.onOrAfter(StoreFileMetaData.FIRST_LUCENE_CHECKSUM_VERSION)) {
checksumFromLuceneFile(directory, segmentsFile, builder, logger, maxVersion, true);
} else {
- final BytesRefBuilder fileHash = new BytesRefBuilder();
- final long length;
- try (final IndexInput in = directory.openInput(segmentsFile, IOContext.READONCE)) {
- length = in.length();
- hashFile(fileHash, new InputStreamIndexInput(in, length), length);
- }
- builder.put(segmentsFile, new StoreFileMetaData(segmentsFile, length, legacyChecksum, maxVersion, fileHash.get()));
+ throw new IllegalStateException("version must be onOrAfter: " + StoreFileMetaData.FIRST_LUCENE_CHECKSUM_VERSION + " but was: " + maxVersion);
}
} catch (CorruptIndexException | IndexNotFoundException | IndexFormatTooOldException | IndexFormatTooNewException ex) {
// we either know the index is corrupted or it's just not there
@@ -898,61 +856,6 @@ public class Store extends AbstractIndexShardComponent implements Closeable, Ref
return new LoadedMetadata(unmodifiableMap(builder), unmodifiableMap(commitUserDataBuilder), numDocs);
}
- /**
- * Reads legacy checksum files found in the directory.
- *
- * Files are expected to start with _checksums- prefix
- * followed by long file version. Only file with the highest version is read, all other files are ignored.
- *
- * @param directory the directory to read checksums from
- * @return a map of file checksums and the checksum file version
- */
- @SuppressWarnings("deprecation") // Legacy checksum needs legacy methods
- static Tuple