Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -571,6 +580,13 @@ public static BlobStoreIndexShardSnapshot fromXContent(XContentParser parser) th
}
}

if (snapshot == null) {
throw new CorruptStateException("snapshot missing");
}
if (indexVersion < 0) {
throw new CorruptStateException("index version missing or corrupt");
}

return new BlobStoreIndexShardSnapshot(
snapshot,
indexVersion,
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 @@ -275,6 +275,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 @@ -53,6 +53,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