Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] [BUG] Bug fix for checksum validation for mapping metadata #15888 #15890

Merged
merged 3 commits into from
Sep 12, 2024
Merged
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 @@ -1299,7 +1299,7 @@ public void writeVerifiableTo(BufferedChecksumStreamOutput out) throws IOExcepti
out.writeByte(state.id());
writeSettingsToStream(settings, out);
out.writeVLongArray(primaryTerms);
out.writeMapValues(mappings, (stream, val) -> val.writeTo(stream));
out.writeMapValues(mappings, (stream, val) -> val.writeVerifiableTo((BufferedChecksumStreamOutput) stream));
out.writeMapValues(aliases, (stream, val) -> val.writeTo(stream));
out.writeMap(customData, StreamOutput::writeString, (stream, val) -> val.writeTo(stream));
out.writeMap(
Expand All @@ -1314,6 +1314,44 @@ public void writeVerifiableTo(BufferedChecksumStreamOutput out) throws IOExcepti
}
}

@Override
public String toString() {
return new StringBuilder().append("IndexMetadata{routingNumShards=")
.append(routingNumShards)
.append(", index=")
.append(index)
.append(", version=")
.append(version)
.append(", state=")
.append(state)
.append(", settingsVersion=")
.append(settingsVersion)
.append(", mappingVersion=")
.append(mappingVersion)
.append(", aliasesVersion=")
.append(aliasesVersion)
.append(", primaryTerms=")
.append(Arrays.toString(primaryTerms))
.append(", aliases=")
.append(aliases)
.append(", settings=")
.append(settings)
.append(", mappings=")
.append(mappings)
.append(", customData=")
.append(customData)
.append(", inSyncAllocationIds=")
.append(inSyncAllocationIds)
.append(", rolloverInfos=")
.append(rolloverInfos)
.append(", isSystem=")
.append(isSystem)
.append(", context=")
.append(context)
.append("}")
.toString();
}

public boolean isSystem() {
return isSystem;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.index.mapper.DocumentMapper;
import org.opensearch.index.mapper.MapperService;
import org.opensearch.index.translog.BufferedChecksumStreamOutput;

import java.io.IOException;
import java.io.UncheckedIOException;
Expand Down Expand Up @@ -168,6 +169,12 @@ public void writeTo(StreamOutput out) throws IOException {
}
}

public void writeVerifiableTo(BufferedChecksumStreamOutput out) throws IOException {
out.writeString(type());
source().writeVerifiableTo(out);
out.writeBoolean(routingRequired);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.opensearch.core.compress.CompressorRegistry;
import org.opensearch.core.xcontent.ToXContent;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.index.translog.BufferedChecksumStreamOutput;

import java.io.IOException;
import java.io.OutputStream;
Expand Down Expand Up @@ -169,6 +170,10 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeByteArray(bytes);
}

public void writeVerifiableTo(BufferedChecksumStreamOutput out) throws IOException {
out.writeInt(crc32);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,30 @@ public void testWriteVerifiableTo() throws IOException {
),
randomNonNegativeLong()
);

String mappings = " {\n"
+ " \"_doc\": {\n"
+ " \"properties\": {\n"
+ " \"actiongroups\": {\n"
+ " \"type\": \"text\",\n"
+ " \"fields\": {\n"
+ " \"keyword\": {\n"
+ " \"type\": \"keyword\",\n"
+ " \"ignore_above\": 256\n"
+ " }\n"
+ " }\n"
+ " },\n"
+ " \"allowlist\": {\n"
+ " \"type\": \"text\",\n"
+ " \"fields\": {\n"
+ " \"keyword\": {\n"
+ " \"type\": \"keyword\",\n"
+ " \"ignore_above\": 256\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ " }";
IndexMetadata metadata1 = IndexMetadata.builder("foo")
.settings(
Settings.builder()
Expand All @@ -220,11 +243,13 @@ public void testWriteVerifiableTo() throws IOException {
.putRolloverInfo(info1)
.putRolloverInfo(info2)
.putInSyncAllocationIds(0, Set.of("1", "2", "3"))
.putMapping(mappings)
.build();

BytesStreamOutput out = new BytesStreamOutput();
BufferedChecksumStreamOutput checksumOut = new BufferedChecksumStreamOutput(out);
metadata1.writeVerifiableTo(checksumOut);
assertNotNull(metadata1.toString());

IndexMetadata metadata2 = IndexMetadata.builder(metadata1.getIndex().getName())
.settings(
Expand All @@ -246,6 +271,7 @@ public void testWriteVerifiableTo() throws IOException {
.putRolloverInfo(info2)
.putRolloverInfo(info1)
.putInSyncAllocationIds(0, Set.of("3", "1", "2"))
.putMapping(mappings)
.build();

BytesStreamOutput out2 = new BytesStreamOutput();
Expand Down
Loading