Skip to content

Commit

Permalink
Add repository metadata integrity check API
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveCTurner committed Jun 14, 2024
1 parent 2aade9d commit 0571ead
Show file tree
Hide file tree
Showing 11 changed files with 2,340 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.xcontent.XContentParserUtils;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.gateway.CorruptStateException;
import org.elasticsearch.index.store.StoreFileMetadata;
import org.elasticsearch.xcontent.ParseField;
import org.elasticsearch.xcontent.ToXContentFragment;
Expand Down Expand Up @@ -318,7 +319,10 @@ public static FileInfo fromXContent(XContentParser parser) throws IOException {
}
case WRITER_UUID -> {
writerUuid = new BytesRef(parser.binaryValue());
assert writerUuid.length > 0;
assert BlobStoreIndexShardSnapshots.INTEGRITY_ASSERTIONS_ENABLED == false || writerUuid.length > 0;
if (writerUuid.length == 0) {
throw new ElasticsearchParseException("invalid (empty) writer uuid");
}
}
default -> XContentParserUtils.throwUnknownField(currentFieldName, parser);
}
Expand All @@ -336,6 +340,11 @@ public static FileInfo fromXContent(XContentParser parser) throws IOException {
} else if (checksum == null) {
throw new ElasticsearchParseException("missing checksum for name [" + name + "]");
}
try {
org.apache.lucene.util.Version.parse(writtenBy);
} catch (Exception e) {
throw new ElasticsearchParseException("invalid written_by [" + writtenBy + "]");
}
return new FileInfo(name, new StoreFileMetadata(physicalName, length, checksum, writtenBy, metaHash, writerUuid), partSize);
}

Expand Down Expand Up @@ -566,6 +575,10 @@ public static BlobStoreIndexShardSnapshot fromXContent(XContentParser parser) th
}
}

if (snapshot == null) {
throw new CorruptStateException("snapshot missing");
}

return new BlobStoreIndexShardSnapshot(
snapshot,
indexFiles == null ? List.of() : indexFiles,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
return builder;
}

static volatile boolean INTEGRITY_ASSERTIONS_ENABLED = true;

public static BlobStoreIndexShardSnapshots fromXContent(XContentParser parser) throws IOException {
XContentParser.Token token = parser.currentToken();
if (token == null) { // New parser
Expand Down Expand Up @@ -309,7 +311,11 @@ public static BlobStoreIndexShardSnapshots fromXContent(XContentParser parser) t
List<FileInfo> fileInfosBuilder = new ArrayList<>();
for (String file : entry.v2()) {
FileInfo fileInfo = files.get(file);
assert fileInfo != null;
if (fileInfo == null) {
final var exception = new IllegalStateException("shard index inconsistent at file [" + file + "]");
assert INTEGRITY_ASSERTIONS_ENABLED == false : exception;
throw exception;
}
fileInfosBuilder.add(fileInfo);
}
snapshots.add(new SnapshotFiles(entry.v1(), Collections.unmodifiableList(fileInfosBuilder), historyUUIDs.get(entry.v1())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ public Collection<SnapshotId> getSnapshotIds() {
return snapshotIds.values();
}

public long getIndexSnapshotCount() {
return indexSnapshots.values().stream().mapToLong(List::size).sum();
}

/**
* @return whether some of the {@link SnapshotDetails} of the given snapshot are missing, due to BwC, so that they must be loaded from
* the {@link SnapshotInfo} blob instead.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

package org.elasticsearch.index.snapshots.blobstore;

import org.elasticsearch.core.Releasable;

public class BlobStoreIndexShardSnapshotsIntegritySuppressor implements Releasable {

public BlobStoreIndexShardSnapshotsIntegritySuppressor() {
BlobStoreIndexShardSnapshots.INTEGRITY_ASSERTIONS_ENABLED = false;
}

@Override
public void close() {
BlobStoreIndexShardSnapshots.INTEGRITY_ASSERTIONS_ENABLED = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public class Constants {
"cluster:admin/repository/get",
"cluster:admin/repository/put",
"cluster:admin/repository/verify",
"cluster:admin/repository/verify_integrity",
"cluster:admin/reroute",
"cluster:admin/script/delete",
"cluster:admin/script/get",
Expand Down
Loading

0 comments on commit 0571ead

Please sign in to comment.