Skip to content

Commit

Permalink
Moving codec to version 2 for compatibility with manifest parser
Browse files Browse the repository at this point in the history
Signed-off-by: Himshikha Gupta <[email protected]>
  • Loading branch information
Himshikha Gupta committed May 14, 2024
1 parent 88d266f commit 4c97869
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,10 @@ public static ClusterMetadataManifest fromXContentV0(XContentParser parser) thro
return PARSER_V0.parse(parser, null);
}

public static ClusterMetadataManifest fromXContentV1(XContentParser parser) throws IOException {
return PARSER_V1.parse(parser, null);
}

public static ClusterMetadataManifest fromXContent(XContentParser parser) throws IOException {
return CURRENT_PARSER.parse(parser, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,13 @@ public class RemoteClusterStateService implements Closeable {
new ChecksumBlobStoreFormat<>("cluster-metadata-manifest", METADATA_MANIFEST_NAME_FORMAT, ClusterMetadataManifest::fromXContentV0);

/**
* Manifest format compatible with codec v1, where we introduced codec versions/global metadata.
* Manifest format compatible with older codec v1, where codec versions/global metadata was introduced.
*/
public static final ChecksumBlobStoreFormat<ClusterMetadataManifest> CLUSTER_METADATA_MANIFEST_FORMAT_V1 =
new ChecksumBlobStoreFormat<>("cluster-metadata-manifest", METADATA_MANIFEST_NAME_FORMAT, ClusterMetadataManifest::fromXContentV1);

/**
* Manifest format compatible with codec v2, where we introduced routing table metadata in manifest.
*/
public static final ChecksumBlobStoreFormat<ClusterMetadataManifest> CLUSTER_METADATA_MANIFEST_FORMAT = new ChecksumBlobStoreFormat<>(
"cluster-metadata-manifest",
Expand Down Expand Up @@ -172,7 +178,7 @@ public class RemoteClusterStateService implements Closeable {
private final AtomicBoolean deleteStaleMetadataRunning = new AtomicBoolean(false);
private final RemotePersistenceStats remoteStateStats;
public static final int INDEX_METADATA_CURRENT_CODEC_VERSION = 1;
public static final int MANIFEST_CURRENT_CODEC_VERSION = ClusterMetadataManifest.CODEC_V1;
public static final int MANIFEST_CURRENT_CODEC_VERSION = ClusterMetadataManifest.CODEC_V2;
public static final int GLOBAL_METADATA_CURRENT_CODEC_VERSION = 1;

// ToXContent Params with gateway mode.
Expand Down Expand Up @@ -1175,6 +1181,8 @@ private ChecksumBlobStoreFormat<ClusterMetadataManifest> getClusterMetadataManif
long codecVersion = getManifestCodecVersion(fileName);
if (codecVersion == MANIFEST_CURRENT_CODEC_VERSION) {
return CLUSTER_METADATA_MANIFEST_FORMAT;
} else if (codecVersion == ClusterMetadataManifest.CODEC_V1) {
return CLUSTER_METADATA_MANIFEST_FORMAT_V1;
} else if (codecVersion == ClusterMetadataManifest.CODEC_V0) {
return CLUSTER_METADATA_MANIFEST_FORMAT_V0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void testClusterMetadataManifestXContentV0() throws IOException {
}
}

public void testClusterMetadataManifestXContent() throws IOException {
public void testClusterMetadataManifestXContentV1() throws IOException {
UploadedIndexMetadata uploadedIndexMetadata = new UploadedIndexMetadata("test-index", "test-uuid", "/test/upload/path");
ClusterMetadataManifest originalManifest = new ClusterMetadataManifest(
1L,
Expand All @@ -75,7 +75,7 @@ public void testClusterMetadataManifestXContent() throws IOException {
builder.endObject();

try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) {
final ClusterMetadataManifest fromXContentManifest = ClusterMetadataManifest.fromXContent(parser);
final ClusterMetadataManifest fromXContentManifest = ClusterMetadataManifest.fromXContentV1(parser);
assertEquals(originalManifest, fromXContentManifest);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ public void testWriteIncrementalMetadataSuccess() throws IOException {
* In final manifest codec version should be 1 and
* global metadata should be updated, even if it was not changed in this cluster state update
*/
public void testMigrationFromCodecV0ManifestToCodecV1Manifest() throws IOException {
public void testMigrationFromCodecV0ManifestToCodecV2Manifest() throws IOException {
mockBlobStoreObjects();
final CoordinationMetadata coordinationMetadata = CoordinationMetadata.builder().term(1L).build();
final ClusterState previousClusterState = ClusterState.builder(ClusterName.DEFAULT)
Expand Down Expand Up @@ -481,7 +481,7 @@ public void testMigrationFromCodecV0ManifestToCodecV1Manifest() throws IOExcepti
// global metadata is updated
assertThat(manifestAfterUpdate.getGlobalMetadataFileName(), notNullValue());
// Manifest file with codec version with 1 is updated.
assertThat(manifestAfterUpdate.getCodecVersion(), is(ClusterMetadataManifest.CODEC_V1));
assertThat(manifestAfterUpdate.getCodecVersion(), is(ClusterMetadataManifest.CODEC_V2));
}

public void testWriteIncrementalGlobalMetadataSuccess() throws IOException {
Expand Down Expand Up @@ -803,6 +803,8 @@ public void testReadGlobalMetadata() throws IOException {
.nodeId("nodeA")
.opensearchVersion(VersionUtils.randomOpenSearchVersion(random()))
.previousClusterUUID("prev-cluster-uuid")
.routingTableVersion(1)
.indicesRouting(List.of())
.build();

Metadata expactedMetadata = Metadata.builder().persistentSettings(Settings.builder().put("readonly", true).build()).build();
Expand Down Expand Up @@ -1464,7 +1466,7 @@ private void mockBlobContainerForGlobalMetadata(
ClusterMetadataManifest clusterMetadataManifest,
Metadata metadata
) throws IOException {
String mockManifestFileName = "manifest__1__2__C__456__1";
String mockManifestFileName = "manifest__1__2__C__456__2";
BlobMetadata blobMetadata = new PlainBlobMetadata(mockManifestFileName, 1);
when(
blobContainer.listBlobsByPrefixInSortedOrder(
Expand Down

0 comments on commit 4c97869

Please sign in to comment.