Skip to content

Commit 1dba8c3

Browse files
[Backport 2.x] [BUG] Bug fix for checksum validation for mapping metadata #15888 (#15890) (#15908)
* [BUG] Bug fix for checksum validation for mapping metadata (#15885) Signed-off-by: Himshikha Gupta <[email protected]>
1 parent 07d1e16 commit 1dba8c3

File tree

4 files changed

+78
-2
lines changed

4 files changed

+78
-2
lines changed

server/src/main/java/org/opensearch/cluster/metadata/IndexMetadata.java

+39-1
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,7 @@ public void writeVerifiableTo(BufferedChecksumStreamOutput out) throws IOExcepti
12991299
out.writeByte(state.id());
13001300
writeSettingsToStream(settings, out);
13011301
out.writeVLongArray(primaryTerms);
1302-
out.writeMapValues(mappings, (stream, val) -> val.writeTo(stream));
1302+
out.writeMapValues(mappings, (stream, val) -> val.writeVerifiableTo((BufferedChecksumStreamOutput) stream));
13031303
out.writeMapValues(aliases, (stream, val) -> val.writeTo(stream));
13041304
out.writeMap(customData, StreamOutput::writeString, (stream, val) -> val.writeTo(stream));
13051305
out.writeMap(
@@ -1314,6 +1314,44 @@ public void writeVerifiableTo(BufferedChecksumStreamOutput out) throws IOExcepti
13141314
}
13151315
}
13161316

1317+
@Override
1318+
public String toString() {
1319+
return new StringBuilder().append("IndexMetadata{routingNumShards=")
1320+
.append(routingNumShards)
1321+
.append(", index=")
1322+
.append(index)
1323+
.append(", version=")
1324+
.append(version)
1325+
.append(", state=")
1326+
.append(state)
1327+
.append(", settingsVersion=")
1328+
.append(settingsVersion)
1329+
.append(", mappingVersion=")
1330+
.append(mappingVersion)
1331+
.append(", aliasesVersion=")
1332+
.append(aliasesVersion)
1333+
.append(", primaryTerms=")
1334+
.append(Arrays.toString(primaryTerms))
1335+
.append(", aliases=")
1336+
.append(aliases)
1337+
.append(", settings=")
1338+
.append(settings)
1339+
.append(", mappings=")
1340+
.append(mappings)
1341+
.append(", customData=")
1342+
.append(customData)
1343+
.append(", inSyncAllocationIds=")
1344+
.append(inSyncAllocationIds)
1345+
.append(", rolloverInfos=")
1346+
.append(rolloverInfos)
1347+
.append(", isSystem=")
1348+
.append(isSystem)
1349+
.append(", context=")
1350+
.append(context)
1351+
.append("}")
1352+
.toString();
1353+
}
1354+
13171355
public boolean isSystem() {
13181356
return isSystem;
13191357
}

server/src/main/java/org/opensearch/cluster/metadata/MappingMetadata.java

+7
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.opensearch.core.xcontent.XContentBuilder;
4747
import org.opensearch.index.mapper.DocumentMapper;
4848
import org.opensearch.index.mapper.MapperService;
49+
import org.opensearch.index.translog.BufferedChecksumStreamOutput;
4950

5051
import java.io.IOException;
5152
import java.io.UncheckedIOException;
@@ -168,6 +169,12 @@ public void writeTo(StreamOutput out) throws IOException {
168169
}
169170
}
170171

172+
public void writeVerifiableTo(BufferedChecksumStreamOutput out) throws IOException {
173+
out.writeString(type());
174+
source().writeVerifiableTo(out);
175+
out.writeBoolean(routingRequired);
176+
}
177+
171178
@Override
172179
public boolean equals(Object o) {
173180
if (this == o) return true;

server/src/main/java/org/opensearch/common/compress/CompressedXContent.java

+5
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.opensearch.core.compress.CompressorRegistry;
4545
import org.opensearch.core.xcontent.ToXContent;
4646
import org.opensearch.core.xcontent.XContentBuilder;
47+
import org.opensearch.index.translog.BufferedChecksumStreamOutput;
4748

4849
import java.io.IOException;
4950
import java.io.OutputStream;
@@ -169,6 +170,10 @@ public void writeTo(StreamOutput out) throws IOException {
169170
out.writeByteArray(bytes);
170171
}
171172

173+
public void writeVerifiableTo(BufferedChecksumStreamOutput out) throws IOException {
174+
out.writeInt(crc32);
175+
}
176+
172177
@Override
173178
public boolean equals(Object o) {
174179
if (this == o) return true;

server/src/test/java/org/opensearch/cluster/metadata/IndexMetadataTests.java

+27-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,30 @@ public void testWriteVerifiableTo() throws IOException {
199199
),
200200
randomNonNegativeLong()
201201
);
202-
202+
String mappings = " {\n"
203+
+ " \"_doc\": {\n"
204+
+ " \"properties\": {\n"
205+
+ " \"actiongroups\": {\n"
206+
+ " \"type\": \"text\",\n"
207+
+ " \"fields\": {\n"
208+
+ " \"keyword\": {\n"
209+
+ " \"type\": \"keyword\",\n"
210+
+ " \"ignore_above\": 256\n"
211+
+ " }\n"
212+
+ " }\n"
213+
+ " },\n"
214+
+ " \"allowlist\": {\n"
215+
+ " \"type\": \"text\",\n"
216+
+ " \"fields\": {\n"
217+
+ " \"keyword\": {\n"
218+
+ " \"type\": \"keyword\",\n"
219+
+ " \"ignore_above\": 256\n"
220+
+ " }\n"
221+
+ " }\n"
222+
+ " }\n"
223+
+ " }\n"
224+
+ " }\n"
225+
+ " }";
203226
IndexMetadata metadata1 = IndexMetadata.builder("foo")
204227
.settings(
205228
Settings.builder()
@@ -220,11 +243,13 @@ public void testWriteVerifiableTo() throws IOException {
220243
.putRolloverInfo(info1)
221244
.putRolloverInfo(info2)
222245
.putInSyncAllocationIds(0, Set.of("1", "2", "3"))
246+
.putMapping(mappings)
223247
.build();
224248

225249
BytesStreamOutput out = new BytesStreamOutput();
226250
BufferedChecksumStreamOutput checksumOut = new BufferedChecksumStreamOutput(out);
227251
metadata1.writeVerifiableTo(checksumOut);
252+
assertNotNull(metadata1.toString());
228253

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

251277
BytesStreamOutput out2 = new BytesStreamOutput();

0 commit comments

Comments
 (0)